Why would gradle build still run the deleted jar task?


I’m trying to find a way to ‘replace’ the default jar task and found (without using overwrite, which should, according to Peter, not be used) this , at least for me, unexpected behaviour (this is some kind of followup to http://forums.gradle.org/gradle/topics/duplicate-files-in-jar).

With the code below gradle prints “correct jar” when running ‘gradle clean jar’. Surprising is that ‘grade clean build’ prints “wrong jar”. It is still calling the original jar task allthough I have deleted it.

Another interesting behaviour is, that if I rename the new jar task to something else, let’s say ‘myJar’, ‘gradle clean jar’ will run ‘myJar’ (isn’t it unconnect and should not be called?) while ‘grade clean build’ will still run the original jar task.

I find this very confusing, is this some kind of bug or is this expected?

jar { //

enabled true

doLast {

println “#### WRONG JAR ####”

} }


task jar (type: Jar) {

dependsOn ‘classes’

from “$buildDir/plugin”

doLast {

println “#### CORRECT JAR ####”

} }

// does not change output. //build.dependsOn jar

As far as I know, tasks cannot be removed.