This plugin allows to use Node.js script and tools via gradle. NodeJs will be downloaded automatically and reused across execution.
plugins { id("de.solugo.nodejs") version "..." } nodejs { version.set("...") // default: "18.16.0" cachePath.set("...") // default: "~/.gradle/nodejs" rootPath.set("...") // default: projectDir }
Run node script
gradle node<ScriptName> -Pargs="..." // node <script-name>.js <args>
Run npm script
gradle npm<TaskName> -Pargs="..." // npm <task-name> <args>
Run yarn task
gradle yarn<TaskName> -Pargs="..." // yarn <task-name> <args>
Run node module
gradle npx<ModuleName> -Pargs="..." // npx <module-name>.js <args>
gradle npmInstall -Pargs="--save-dev react"
nodejs {
rootPath("./frontend")
}
tasks.create("buildFrontend") {
doFirst {
nodejs.execNpm("ci")
nodejs.execNpm("run", "build")
}
}
tasks.create("testPackage") {
doFirst {
nodejs.exec {
workingDir("../package")
args(resolveBinary("npm"), "run", "test")
}
}
}