gradle-node-plugin icon indicating copy to clipboard operation
gradle-node-plugin copied to clipboard

Setting NPM repository as part of build.gradle

Open rootinfection opened this issue 9 years ago • 10 comments

Is there anyway to change the default npm repository within the buildscript dependencies, rather than changing configuration on the system.

rootinfection avatar Sep 26 '16 16:09 rootinfection

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]
}

johnmartel avatar Nov 02 '16 16:11 johnmartel

Creating a .npmrc with:

registry = "http://artifactory.domain.com/artifactory/api/npm/NPM-Main/"

worked. Thanks @johnmartel

BroHammie avatar Nov 21 '16 22:11 BroHammie

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?

jakemonO avatar Jun 20 '17 16:06 jakemonO

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)

BroHammie avatar Jun 20 '17 16:06 BroHammie

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.

mconner avatar Aug 01 '17 16:08 mconner

I have the same problem as @mconner. Is there a solution for that?

greenarr0w avatar Oct 18 '17 17:10 greenarr0w

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 avatar Jan 25 '19 13:01 john3300

@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/']
}

dlangerenken avatar Jan 28 '19 06:01 dlangerenken

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.

john3300 avatar Jan 28 '19 15:01 john3300

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.

john3300 avatar Jan 28 '19 19:01 john3300