Setting NPM repository as part of build.gradle
Is there anyway to change the default npm repository within the buildscript dependencies, rather than changing configuration on the system.
You can always provide a .npmrc file, with the registry and _auth properties set to whatever fits your case. If you need the _auth property to be injectable, set it to an environment variable that can be set by configuring the npm_publish task by setting the environment map:
npm_publish {
environment = ['AUTH_TOKEN': project.authToken]
}
Creating a .npmrc with:
registry = "http://artifactory.domain.com/artifactory/api/npm/NPM-Main/"
worked. Thanks @johnmartel
where does one put the npmrc file? in the project root? (next to build.grade) or in the node (subproject root (next to package.json) or somewhere else?
According to the npmrc doc page:
FILES
The four relevant files are:
per-project config file (/path/to/my/project/.npmrc)
per-user config file (~/.npmrc)
global config file ($PREFIX/etc/npmrc)
npm builtin config file (/path/to/npm/npmrc)
I have mine at the per-project level(next to package.json)
I'm using version 1.2.0 of the plugin, configured for node 6.11.1 and npm 3.10.10. When I set the registry in ~/.npmrc, it properly accesses our npm proxy repo (nexus). When I move that file to my project (same directory as the package.json and build.gradle, in this case), it does not work. Executing:
./gradlew npmInstall runs nodeSetup just fine, but chokes on npmSetup with:
...
npm ERR! Error: connect ECONNREFUSED 151.101.56.162:443
...
Edit: so the .npmrc does work after npmSetup is run, but npmSetup doesn't honor the project-level .npmrc. This is addressed in #226, by setting the --registry command line arg.
I have the same problem as @mconner. Is there a solution for that?
Use of the .npmrc file to set the repository won't work for my use case. We aren't developing the project, we are just using NPM to download other peoples tools (code validators mainly) that we run as part of our build. Since we don't have control of those projects I can't drop a .npmrc file into them.
And we have a very distributed build environment, including individual developer's local boxes, so putting it in the home directory is not feasible either.
We really need something that we can set in the build.gradle file that the plugin will pick and handle for us.
@john3300 have you seen the workaround described in https://github.com/srs/gradle-node-plugin/issues/226 ?
afterEvaluate() {
npmSetup.args += ['--registry=https://some.url/here/']
}
No, I had not seen that before. Thanks @dlangerenken!
Is there an easy way to verify what registry it's connecting to? I can't find any kind of debug or verbose flag for the npm command.
I found the --verbose option gave me the output I was looking for. However the afterEvaluate() block did not work. It encouraged me to look for other alternatives though.
The one I found that worked was to add --registry=https://some.url/here/ to the args of my NpmTask.
I still think this should be a supported config parameter in the node configuration block, but this will get me by for now.