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 = '1.2.3.4'
...
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-1.2.3.4.zip. Is whenReady too late to reconfigure the Zip task? This trick works for my jar artifacts but not my Zip task. (Gradle M6)