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

Add possibility to download nodejs binary once and re-use it in different modules

Open Schahen opened this issue 5 years ago • 5 comments

Hi! Correct me if I'm wrong but from what I see user of gradle-node-plugin is supposed to choose between two options:

  1. to download specific version of node.js
  2. to rely on existence of globally installed node.js

However in multimodule projects there's quite often a need to be able to download nodejs once but to point to that particular binary everywhere.

Again, correct me if I'm wrong, but from what I see reading the code - if, say, N modules are configure like this:

node {
    workDir = ...

    version = gradle.nodeVersion
    npmVersion = gradle.npmVersion
    yarnVersion = gradle.yarnVersion

    nodeModulesDir = ... // subproject-specific node_modules path
    download = true
}

than nodejs will be downloaded N times and every next module will start with deleting nodejs distrib installed by previous one. Not only this is suboptimal but introduces lost of unpredicted troubles (for instance, with a parallel build)

So I'm either asking: Is there a way to download nodejs only once and reuse it in different modules?

If the answer is positive than I would like to know how exactly it can be done. If there's no such feature I'd be glad to propose it and even to implement if needed.

Schahen avatar Jul 13 '20 12:07 Schahen

This is a duplicate of #61 although with a more descriptive title.

The easiest workaround I can think of right now is to set download = true in one project, false in all others and then modify the environment variable PATH to point to the download directory from the first.

Possibly adding a Copy task that moves it to a directory with a predictable name, letting nodeSetup be finalizedBy it

deepy avatar Jul 13 '20 13:07 deepy

With that said, this is a feature we really want it just hasn't been given the highest priority since it's a bit tricky to implement but we're open to pretty much all ways of solving this!

deepy avatar Jul 13 '20 13:07 deepy

since it's a bit tricky to implement

can you elaborate on why this is tricky? I would have imagined that the plugin could just always use <root project>/.gradle to store node js or yarn versions. The setup tasks would also always belong to the root project (if multiple versions are used, there are multiple tasks), so Gradle’s task management automatically ensures synchronization.

This sounds straightforward enough in my head, where is the catch?

jGleitz avatar Sep 02 '20 08:09 jGleitz

Any updates on this? We have a gradle multimodule build where we would like to use the same nodejs version in two sub-modules without downloading it twice.

However i could not manage to get this working.

sebastianzillessen avatar Jul 31 '23 09:07 sebastianzillessen

I'm starting my vacation soon and will take another look at how to do this in a good way (or document the bad way as an example) But there's a configuration-cache issue in one of the nightlies I need to look at first and the test suite needs some improvements before I can get started

deepy avatar Jul 31 '23 10:07 deepy