Why does gradle -t keep rebuilding buildSrc


(Christoph Sturm) #1

I’m trying to run my unit test suite continously on code change:

./gradlew -t singletest --tests UnitTestSuite

singletest is just a test task that i created for running single tests that are specified on the commandline
task singletest(type: Test) {
}

the output is like this:

Starting a Gradle Daemon, 1 stopped Daemon could not be reused, use --status for details
Continuous build is an incubating feature.
:buildSrc:compileKotlin UP-TO-DATE
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy NO-SOURCE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestKotlin UP-TO-DATE
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test
:buildSrc:check
:buildSrc:build
Task :jmh Last added: null
:nodeSetup UP-TO-DATE
:createClientRequest
:compileKotlin UP-TO-DATE
:generateAvroProtocol NO-SOURCE
:generateAvroJava NO-SOURCE
:compileJava NO-SOURCE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:generateTestAvroProtocol UP-TO-DATE
:generateTestAvroJava UP-TO-DATE
:compileTestKotlin UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:singletest UP-TO-DATE

BUILD SUCCESSFUL in 6s
10 actionable tasks: 1 executed, 9 up-to-date

Waiting for changes to input files of tasks...

then i change one file, and like expected the singletest target runs again. but for some reason the buildSrc tasks also run,

new file: ...<censored>
Change detected, executing build...

:buildSrc:compileKotlin UP-TO-DATE
:buildSrc:compileJava NO-SOURCE
:buildSrc:compileGroovy NO-SOURCE
:buildSrc:processResources UP-TO-DATE
:buildSrc:classes UP-TO-DATE
:buildSrc:jar UP-TO-DATE
:buildSrc:assemble UP-TO-DATE
:buildSrc:compileTestKotlin UP-TO-DATE
:buildSrc:compileTestJava NO-SOURCE
:buildSrc:compileTestGroovy NO-SOURCE
:buildSrc:processTestResources NO-SOURCE
:buildSrc:testClasses UP-TO-DATE
:buildSrc:test
:buildSrc:check
:buildSrc:build
Task :jmh Last added: null
:nodeSetup UP-TO-DATE
:createClientRequest
:compileKotlin UP-TO-DATE
:generateAvroProtocol NO-SOURCE
:generateAvroJava NO-SOURCE
:compileJava NO-SOURCE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:generateTestAvroProtocol UP-TO-DATE
:generateTestAvroJava UP-TO-DATE
:compileTestKotlin
Using Kotlin incremental compilation
:compileTestJava
:processTestResourcesNote: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
 UP-TO-DATE
:testClasses
:singletest

Is that a bug? is there a workaround? can i just specify -x to make it not build buildSrc as a workaround?


(Sterling Greene) #2

This is normal. buildSrc is a separate build that needs to be checked for up-to-date-ness before executing the root build. Unless something has changed in buildSrc, all of its tasks are up-to-date.


(Christoph Sturm) #3

I agree that it should be checked, but why does it run the tasks? they should be up to date.
it seems all these 3 tasks run at every build:

:buildSrc:test
:buildSrc:check
:buildSrc:build

(Sterling Greene) #4

Something seems to be making :buildSrc:test out of date. If you run with -i, you’ll see a message like:

Executing task ‘:buildSrc:test’ (up-to-date check took 0.002 secs) due to:

followed by a reason.

You could also try generating a build scan for your buildSrc project (you have to do this from the buildSrc directory):

cd buildSrc
../gradlew -u --scan build

This should have the same kind of information as --info as described here.

check and build are lifecycle tasks. They don’t usually do anything and are only showing they’re not up-to-date because test was not up-to-date.


(Christoph Sturm) #5

running with -i

Executing task ':buildSrc:test' (up-to-date check took 0.003 secs) due to:
  Output property 'reports.enabledDirectoryReportDestinations.html' file /home/christoph/.../buildSrc/build/reports/tests/test/classes/ScriptPrependerTest.html has changed.
  Output property 'reports.enabledDirectoryReportDestinations.html' file /home/christoph/.../buildSrc/build/reports/tests/test/index.html has changed.

so this is really strange. in the first run it runs the test, which is expected, but it also generates a test report, and for some reason that test report is reason enough to run the tests again when the build re-runs

thanks for your help tracking this down!


(Sterling Greene) #6

To rule out anything with -t/--continuous, do you see the same thing happen if you just run the same build over and over manually? Does :buildSrc:test run every time?

Do you have anything special in your buildSrc/build.gradle file?


(Christoph Sturm) #7

ok this is really strange. I tried to reproduce this in 3 different copies of my project and it happens reproducable only in one of them. the one where it continously happens is a directory where i rsynced all files (excluding the build directory) to a faster server to run the continous build there. the strange thing is it keeps happening even when i remove buildSrc/build and buildSrc/.gradle

I’m going to try to find a reduced test for this and in the meantime i assume that its something strange that i was doing with that copy of the sourcecode, maybe some timestamps in the future?