Gradle Node插件代理环境下无法解析私有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
distBaseUrlto 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

