How do get or set the node.exe path in a kmp project

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

Do you have configuration cache enabled, but configuration cache errors degraded to warnings?

Do you have configuration cache enabled

Yes, i do

but configuration cache errors degraded to warnings

I dont know. I will have to check it out

Here is my gradle.properties

# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

#Kotlin
kotlin.incremental=true
kotlin.code.style=official
kotlin.mpp.applyDefaultHierarchyTemplate=false

#Gradle
org.gradle.caching=true
org.gradle.unsafe.configuration-cache-problems=warn
org.gradle.jvmargs=-Xmx5g -XX:MaxMetaspaceSize=3g -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 -XX:+UseParallelGC
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true

#Jetbrains
org.jetbrains.compose.experimental.jscanvas.enabled=true

#Android
android.useAndroidX=true
android.suppressUnsupportedCompileSdk=35
android.experimental.enableNewResourceShrinker.preciseShrinking=true
android.enableR8.fullMode=false
android.nonTransitiveRClass=false
org.gradle.configuration-cache=true

#Publicacao Maven
mavenHAuthHeaderName=XXX
mavenAuthHeaderValue=XXXXXX

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?

Sure:

kotlinNodeJsSpec {
    command = "..."
}

Thank you very much!!!
I dont understand why it is so hard to find this info!

Complain to the KGP maintainers :slight_smile: