Overriding the test task in gradle versions > 1.1 doesn't work as expected


(Gareth Davis) #1

Hi,

I’m seem to have found an unexpected difference between version 1.1 and above.

My build replaces the test task to using something similar to this:

task beforeTest() <<
{
    println "**** - BEFORE THE TEST TASK"
}
  task test(overwrite:true, dependsOn:['beforeTest'])

I’ve created a minium example project https://github.com/gid79/GradleCheck

When I run ‘./gradlew build’ (version 1.1) the output clearly shows the beforeTest task running. but using gradle 1.3 this doesn’t happen.

A copy of the output is https://gist.github.com/4368563

Happy Christmas.

Gareth

PS. I realise I don’t have to overwrite the test task in this example, but in my actual project I really do :slight_smile:


(René Groeschke) #2

Thank you for the detailed report. It seems that the overwrite flag does not replace the original task in the task dependency graph and build still holds a reference on the ‘old’ test task. running

gradle test

or

./gradlew test

works as expected.

cheers, René


(Peter Niederwieser) #3

This is GRADLE-2607. As a workaround, you can manually update the check->test dependency:

apply plugin: "java"
  test << { println "old" }
  check.dependsOn -= test
  task test(overwrite: true) << { println "new" }
  check.dependsOn += test