taskGraph.whenReady fails to configure built-in task

(tinkerer.tech) #1

I am using the taskGraph.hasTask() method in my main (multi-project) build.gradle to detect whether it’s a “release” build or “snapshot” build and then set my artifact version nos according -

def mySpecialProjects = subprojects.findAll { ..
configure(mySpecialProjects) {
           apply plugin : 'java'
           group = 'myGroupID'
           version = ''
           gradle.taskGraph.whenReady { taskGraph ->
 if (taskGraph.hasTask( "${project.path}:release" )) {
         version = version
   } else {
        version = 'SNAPSHOT'
                  task release( dependsOn: "build" ) << {
 println "Releasing " + project.group + ":" + project.name + ":" + project.version

and in my subproject build.gradle I have a Zip task, eg. -

task zipStuff (type: Zip, dependsOn: classes) {
 from 'src/zipmefolder'
 destinationDir buildDir
 baseName "${archivesBaseName}_zippedStuff"
  version project.version
 extension 'zip'

The issue is that the produced artifact is always named **_zippedStuff- Is whenReady too late to reconfigure the Zip task? This trick works for my jar artifacts but not my Zip task. (Gradle M6)

(Peter Niederwieser) #2

The problem is that you are eagerly overwriting ‘zipStuff.version’ in the configuration phase, which comes before the ‘taskGraph.whenReady’ callback. Since the ‘version’ properties of all archive tasks already (lazily) default to ‘project.version’ (thanks to the ‘base’ plugin), things should work once you remove the explicit configuration of the ‘version’ property in ‘zipStuff’.

(tinkerer.tech) #3

Thanks, that explains it well!