You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle Node插件代理环境下无法解析私有Artifactory路径求助

Fixing Gradle Node Plugin Download Failure with Private Artifactory

The core issue here is that the Gradle Node plugin expects a directory structure matching the official Node.js download server (e.g., ${distBaseUrl}/v${version}/ivy.xml), but your private Artifactory uses a different path pattern (http://domain.com/api/npm/node/${version}). Here are three proven solutions to resolve this:

1. Customize the Download URL with a Dynamic Closure

Instead of relying on distBaseUrl, use the plugin's downloadUrl configuration to generate the exact URL your Artifactory expects. This lets you bypass the plugin's default path template entirely.

node {
    version = '10.15.3'
    npmVersion = '6.4.1'
    download = true
    workDir = file("${project.buildDir}/nodejs")
    npmWorkDir = file("${project.buildDir}/npm")

    // Generate the correct download URL based on version, OS, and architecture
    downloadUrl = { String version, String os, String arch ->
        // Replace with your Artifactory's actual path to Node.js binaries
        // Ensure the filename matches the binary hosted in your Artifactory (e.g., node-v10.15.3-linux-x64.tar.gz)
        "http://domain.com/api/npm/node/${version}/node-v${version}-${os}-${arch}.tar.gz"
    }
}

Note: Double-check that the filename in the URL matches exactly what's stored in your Artifactory. If your binaries use a different naming convention, adjust the string accordingly.

2. Align Artifactory Repository Structure with Plugin Expectations

If you have control over your Artifactory setup, create a generic remote repository that proxies the official Node.js download server (https://nodejs.org/dist/). This way, your Artifactory will mirror the official directory structure, making the plugin's default path logic work seamlessly.

  • Configure the Artifactory remote repository to point to https://nodejs.org/dist/
  • Set distBaseUrl to your Artifactory's proxy repository URL, e.g.:
    node {
        version = '10.15.3'
        npmVersion = '6.4.1'
        download = true
        distBaseUrl = 'https://your-artifactory.com/nodejs-proxy'
        workDir = file("${project.buildDir}/nodejs")
        npmWorkDir = file("${project.buildDir}/npm")
    }
    

The plugin will now request ${distBaseUrl}/v10.15.3/ivy.xml, which your Artifactory will proxy to the official Node.js server, resolving the path mismatch.

3. Manually Provide Local Node.js Binary (For Quick Workarounds)

If you need a temporary fix or can't modify Artifactory settings, download the Node.js binary for your target platform manually, then configure the plugin to use the local file:

node {
    version = '10.15.3'
    npmVersion = '6.4.1'
    download = false // Disable automatic download
    workDir = file("${project.buildDir}/nodejs")
    npmWorkDir = file("${project.buildDir}/npm")

    // Point to the local Node executable (adjust path to match your setup)
    nodeExec = file("${project.rootDir}/local-node/node-v10.15.3-linux-x64/bin/node")
}

This is less scalable for multi-environment builds but works for immediate testing.


内容的提问来源于stack exchange,提问作者Rinsen S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 15:47:56