Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do my Gradle tests run repeatedly?

Tags:

gradle

I have a pretty standard Gradle build that's building a Java project.

When I run it for the first time, it compiles everything and runs the tests. When I run it a second time without changing any files, it runs the tests again.

According to this thread, Gradle is supposed to be lazy by defaut and not bother running tests if nothing has changed. Has the default behaviour here been changed?

EDIT:

If I run gradle test repeatedly, the tests only run the first time and are subsequently skipped. However, if I run gradle build repeatedly, the tests get re-run every time, even though all other tasks are marked as up-to-date.

like image 697
dty Avatar asked Oct 23 '25 19:10

dty


1 Answers

OK, so I got the answer thanks to Rene prompting me to look at the '-i' output.

I actually have 2 test tasks: the 'test' one from the Java plugin, and my own 'integrationTest' one. I didn't mention this in the question because I didn't think it was relevant.

It turns out that these tasks are writing their output (reports, etc.) to the same directory, so Gradle's task-based input and output tracking was thinking that something had changed, and re-running the tests.

So the next question is how to cleanly - and with minimal Groovy/Gradle code - separate two instances of the test task.

like image 126
dty Avatar answered Oct 26 '25 14:10

dty



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!