Hy!
I Need to set my project to use an existing installation of nodejs, but i cant find a way to set the path of the executable.
I’ve tried to obtain the path that it is using, with the code below, but it returns an error.
Can someone help me with this?
I need:
-To set the node.exe path to be using when the “download” option is set to false
-To obtaint the path used
tasks.register("printNodePath") {
doLast {
getNodeJsBinaryExecutable()
try {
val nodePath = getNodeJsBinaryExecutable()
println("✅ Node.js path being used in '${project.name}': $nodePath")
} catch (e: Exception) {
println("❌ Error finding Node.js path in '${project.name}': ${e.message}")
}
}
}
fun getNodeJsBinaryExecutable(): String {
val nodeDir = NodeJsRootPlugin.apply(project).nodeJsSetupTaskProvider.get().destination
println("✅ Node.js path being used in '${project.name}': $nodeDir")
val isWindows = System.getProperty("os.name").toLowerCase().contains("windows")
val nodeBinDir = if (isWindows) nodeDir else nodeDir.resolve("bin")
val command = NodeJsRootPlugin.apply(project).nodeCommand
val finalCommand = if (isWindows && command == "node") "node.exe" else command
return nodeBinDir.resolve(finalCommand).absolutePath
}
Execution failed for task ':produtoAIJs:printNodePath'.
> Cannot invoke "Build_gradle.getNodeJsBinaryExecutable()" because "this.this$0" is null
So the answer is yes.
While you use the old “unsafe” option" org.gradle.unsafe.configuration-cache-problems, this still works and degrades the errors to warnings.
This is not a production-level setting.
It is a temporary setting that you can use during a bigger migration to fix multiple things at once.
Using it in production just makes trouble, because … well … it degrades errors to warnings.
Errors are there for a reason.
If you would not have that setting, you build would have failed earlier with a clearer error, that the script instance cannot be serialized.
You try to call a method on the script instance that accesses properties of the script at execution time of a task, and that cannot work, as with the configuration cache, the script instance does not exist but is null.
This null is what you get an error about as you degraded the original error to a warning.
Thank you for your tip
The project is not for production. It is a PoC that i am creating to evaluate the viability of KMP
Anyway its is changed.
(removed the “org.gradle.unsafe.configuration-cache-problems=warn” line)
But, about how to set the node.exe path do you have any clue?