You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I second this wholeheartedly. It really helps to keep things consistent because you can reuse the same npm for multiple needs.
A workaround would be to allow a lazy setup (at execution time) of npm binary. Then the wiring to gradle-node-plugin can be done manually. I've tried a custom npm-setup task and made spotlessInternalRegisterDependencies depend on it but I have no idea how configuration of spotless steps could be altered at execution time (I don't think I can set the npm path then, can I?).
Sorry, I wasn't clear - I know npm path can be set at configuration time. I don't think it can be set afterward, at execution time. This is the difference that would make it possible to run with gradle-node-plugin because then you wire up a dependency between spotless and gradle-node-plugin's npminstall, add a doFirst clause to spotless task and set up the npm path pointing at the right location.
My experiment shows this is currently impossible because npm path resolution takes place eagerly at configuration time.
doFirst runs after@TaskAction, which is surprising. It's only "first" compared to doLast actions, unfortunately. But agreed, there would be more flexibility if you could set the exe at execution time, and I'm happy to merge a PR that does that.
FYI, I use this tiny little buildsrc plugin which lazily installs node at configuration time, to workaround this and other similar issues.
Really? Well, even if then you could just add a task dependency in between to set the exe path - you get the gist. I didn't think about using buildsrc to set up node beforehand, good tip. May look into this, eventually. I'd love to provide a patch but I'm swamped in work already, eh.
Thank you for the great plugin - it's really useful!
Just to share, we're facing this same challenge and have a working setup - but some minor caveats.
This works for us:
plugins {
...
id 'com.diffplug.spotless' version '5.14.2'
id "com.github.node-gradle.node" version "2.2.4"
}
spotless {
java {
prettier(...)
.npmExecutable("$node.variant.npmExec")
.config(...)
}
}
spotlessInternalRegisterDependencies.dependsOn(nodeSetup)
The caveats are:
spotlessInternalRegisterDependencies.dependsOn(nodeSetup) seems to be the only reliable way to make all potential spotless invocations work. The Internal in the name makes this uncomfortable, so I'd be keen to know if there's a better way to specify this task dependency.
Activity
dweiss commentedon Dec 16, 2020
I second this wholeheartedly. It really helps to keep things consistent because you can reuse the same npm for multiple needs.
A workaround would be to allow a lazy setup (at execution time) of npm binary. Then the wiring to gradle-node-plugin can be done manually. I've tried a custom npm-setup task and made spotlessInternalRegisterDependencies depend on it but I have no idea how configuration of spotless steps could be altered at execution time (I don't think I can set the npm path then, can I?).
nedtwigg commentedon Dec 16, 2020
You can set the npm path (docs, code). I think it has to be set at configuration-time, not execution time.
Happy to take a PR to improve this situation.
dweiss commentedon Dec 17, 2020
Sorry, I wasn't clear - I know npm path can be set at configuration time. I don't think it can be set afterward, at execution time. This is the difference that would make it possible to run with gradle-node-plugin because then you wire up a dependency between spotless and gradle-node-plugin's npminstall, add a doFirst clause to spotless task and set up the npm path pointing at the right location.
My experiment shows this is currently impossible because npm path resolution takes place eagerly at configuration time.
nedtwigg commentedon Dec 17, 2020
doFirstruns after@TaskAction, which is surprising. It's only "first" compared todoLastactions, unfortunately. But agreed, there would be more flexibility if you could set the exe at execution time, and I'm happy to merge a PR that does that.FYI, I use this tiny little buildsrc plugin which lazily installs node at configuration time, to workaround this and other similar issues.
dweiss commentedon Dec 17, 2020
Really? Well, even if then you could just add a task dependency in between to set the exe path - you get the gist. I didn't think about using buildsrc to set up node beforehand, good tip. May look into this, eventually. I'd love to provide a patch but I'm swamped in work already, eh.
rnorth commentedon Aug 10, 2021
Thank you for the great plugin - it's really useful!
Just to share, we're facing this same challenge and have a working setup - but some minor caveats.
This works for us:
The caveats are:
spotlessInternalRegisterDependencies.dependsOn(nodeSetup)seems to be the only reliable way to make all potential spotless invocations work. TheInternalin the name makes this uncomfortable, so I'd be keen to know if there's a better way to specify this task dependency.node-gradlerecently removed the property which exposes the path to npm, so we're locked to a specific version of that plugin at present.nedtwigg commentedon Jan 26, 2023
Thanks to a series of great PRs from @simschla, this is now possible in
plugin-gradle 6.14.0. See this or this example.