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

Question on multi-project builds

Open mconner opened this issue 8 years ago • 1 comments

In a multi-project build, I have a shared configuration, that I apply with: ` apply from: '../sharedNodejs.gradle' in two sub-projects. sharedNodejs.gradle contains the plugin configuration:

node {
   ...
    workDir = file("${rootProject.projectDir}/buildtools/nodejs")
    npmWorkDir = file("${rootProject.projectDir}/buildtools/npm")
   ...

}

However, if I run gradlew npmSetup, it keeps executing both, rather than considering it up to date after the first run (looks like the nodeSetup works correctly, thus the 2 up-to-date):

> Task :nodeex:npmSetup
C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10\npm -> C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10\node_modules\npm\bin\npm-cli.js
C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10
`-- [email protected]


> Task :webspa:npmSetup
C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10\npm -> C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10\node_modules\npm\bin\npm-cli.js
C:\dev\gitrepos\ngclimulti\buildtools\npm\npm-v3.10.10
`-- [email protected]
BUILD SUCCESSFUL in 1m 14s
4 actionable tasks: 2 executed, 2 up-to-date
gw started at: Wed Sep  6 11:38:25 CDT 2017, completed at: Wed Sep  6 11:39:42 CDT 2017, Duration: 1 min, 17 seconds

which takes a while.

If I move the node and npm to the projectDir for each project, rather than rootProject.projectDir, then it works as expected, but I'm stuck with two node installs. For an IDE, like IntelliJ, I need to pick a node install, (maybe it doesn't matter which one?)

Am I doing something wrong? Is there a better way to handle this?

mconner avatar Sep 06 '17 16:09 mconner

Am I doing something wrong? Is there a better way to handle this?

No, you made right configuration.

This is plugin issue. It does update operation during task nodeSetup

Expected philosophy:

  • Node plugin should reuse installed binaries (for multimodule projects the same node should be used if the version and repository URL is the same)
  • Each node should be installed into the separate folder
  • Installation folder should not be changed

Actual steps:

  • Plugin installs node into the folder
  • Plugin change file system (see here)
  • As a result:
    • It is unable to simple reuse the same node version
    • Each project has to download node independently

Proposed solution

  • Remark: I can implement it if @srs is ok for kotlin language here and for potential dropping support of the Gradle 4.* and below
  • Create node installation tasks for root project. It means that if project requires node with version X from repository Y then plugin should attach (or find existing) task for the root project named like "node_installation_x_y"
  • This task should:
    • In configuration:
      • Configure inputs/outputs
    • In onLast section:
      • Download file (+ publish updates of course)
  • The most of project-related tasks:
    • Should depend of root-level tasks

imanushin avatar Mar 29 '19 09:03 imanushin