node-gradle / gradle-node-plugin

Gradle plugin for integrating NodeJS in your build. :rocket:
Apache License 2.0
599 stars 117 forks source link

How get `nodeDir` in version 5.0.0? #276

Closed candrews closed 1 year ago

candrews commented 1 year ago

In version 4.0.0, running gradle nodeDir with this build.gradle prints the node directory:

plugins {
    id 'com.github.node-gradle.node' version '4.0.0'
}

node {
    download = true
}

task nodeDir {
    dependsOn nodeSetup
    println nodeSetup.nodeDir.get()
}

However, that doesn't work with version 5.0.0. Here's the build.gradle:

plugins {
    id 'com.github.node-gradle.node' version '5.0.0'
}

node {
    download = true
}

task nodeDir {
    dependsOn nodeSetup
    println nodeSetup.nodeDir.get()
}

The result is:

$ gradle nodeDir

FAILURE: Build failed with an exception.

* Where:
Build file '/tmp/y/build.gradle' line: 11

* What went wrong:
A problem occurred evaluating root project 'y'.
> Cannot query the value of task ':nodeSetup' property 'nodeDir' because it has no value available.

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
[1]

I'm using gradle 8.1.1.

deepy commented 1 year ago

If you change this to doLast {} and use tasks.register() I think that should work, the problem is you're querying the value before it has been set But luckily there's a better place to get this from, it's now also available on the NodeExtension as computedNodeDir:

candrews commented 1 year ago

But luckily there's a better place to get this from, it's now also available on the NodeExtension as computedNodeDir:

I figured it out - this works:

plugins {
    id 'com.github.node-gradle.node' version '5.0.0'
}

node {
    download = true
}

task nodeDir {
    dependsOn nodeSetup
    println node.computedNodeDir.get()
}

Thank you!