taskGraph evaluation and version not being applied confusion

Hi,

Gradle: 1.3. Java 1.7u10.

I have the following code block configured in my build.gradle:

gradle.taskGraph.whenReady { taskGraph ->
    if(!taskGraph.hasTask(release)) {
        appVersion += '-SNAPSHOT'
    } else {
        appVersion += '-RELEASE'
    }
   }
  configure(subprojects) {
    version = appVersion
}

In my gradle.properties, I have:

appVersion = 3.6.0

Yet, all WARs do not get the 3.6.0-SNAPSHOT appended to their name when I do “gradle war”, instead they only have widget-3.6.0.war.

I’m doing something wrong… :slight_smile:

Any help would be appreciated. Thank you.

Hi,

I think I have solved it.

Here is a snippet of my build.gradle:

configure(allprojects) {
    group = 'abc.def'
    version = appVersion
      gradle.taskGraph.whenReady { taskGraph ->
        if(taskGraph.hasTask(release)) {
            version += '-RELEASE'
        } else {
            version += '-SNAPSHOT'
        }
       }
   }

The important thing to note is this. Firstly, applying the gradle.taskGraph.whenReady inside allprojects and it appears that the gradle.taskGraph.whenReady is evaulated after allprojects have been configured. You will note that I set the version to be appVersion first (which is 3.6.0), then after the evaluation, the version changes to 3.6.0-RELEASE (or -SNAPSHOT).

I’ve tested this out with my sub projects and each WAR now has either abc-3.6.0-RELEASE.war or abc-3.6.0-SNAPSHOT.war appended correctly.

I hope this is of benefit to some others :slight_smile:

Hi David,

Thank you for posting back your findings. I’m sure others will benefit.

it appears that the gradle.taskGraph.whenReady is evaulated after allprojects have been configured

That’s correct. Gradle configures the project model (i.e. evaluates all the build scripts), then assembles the task graph based on what it finds out.