I have a simple, four file multi-project build using the java plugin in M5. If I set the sub projects testReportDir to a location in the root project, the projects are never up to date. Details below.
You can download a zip of the sample project from here.
Files are as follows:
structure:
. ├── build.gradle ├── one │ └── src │├── main │
│ └── java │
│
└── org │
│
└── gradle │
│
└── bug │
│
└── SampleClass.java │
└── test │
└── java │
└── org │
└── gradle │
└── bug │
└── TestSampleClass.java └── settings.gradle
settings.gradle
include ':one'
build.gradle
allprojects {
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
testCompile "junit:junit:4.8.2"
}
test {
testResultsDir = rootProject.testResultsDir
//testReportDir = rootProject.testReportDir
}
}
The issue here is that I need aggregated test reports for the multi-project build and if I comment in the testReportDir setting above, the tasks [test, check, build] are never up to date.
Execution sample:
nadurra:uptodatetest mbjarland$ gradle --daemon clean
Note: the Gradle build daemon is an experimental feature.
As such, you may experience unexpected build failures. You may need to occasionally stop the daemon.
:clean
:one:clean
BUILD SUCCESSFUL
Total time: 0.851 secs
nadurra:uptodatetest mbjarland$ gradle --daemon build
Note: the Gradle build daemon is an experimental feature.
As such, you may experience unexpected build failures. You may need to occasionally stop the daemon.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
:check
:build
:one:compileJava
:one:processResources UP-TO-DATE
:one:classes
:one:jar
:one:assemble
:one:compileTestJava
:one:processTestResources UP-TO-DATE
:one:testClasses
:one:test
:one:check
:one:build
BUILD SUCCESSFUL
Total time: 2.264 secs
nadurra:uptodatetest mbjarland$ touch stamp && gradle --daemon build
Note: the Gradle build daemon is an experimental feature.
As such, you may experience unexpected build failures. You may need to occasionally stop the daemon.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test
:check
:build
:one:compileJava UP-TO-DATE
:one:processResources UP-TO-DATE
:one:classes UP-TO-DATE
:one:jar UP-TO-DATE
:one:assemble UP-TO-DATE
:one:compileTestJava UP-TO-DATE
:one:processTestResources UP-TO-DATE
:one:testClasses UP-TO-DATE
:one:test
:one:check
:one:build
BUILD SUCCESSFUL
Total time: 2.135 secs
nadurra:uptodatetest mbjarland$ find . -newer stamp
./.gradle/1.0-milestone-5/fileHashes/cache.bin
./.gradle/1.0-milestone-5/fileHashes/cache.properties.lock
./.gradle/1.0-milestone-5/fileSnapshots/cache.bin
./.gradle/1.0-milestone-5/fileSnapshots/cache.properties.lock
./.gradle/1.0-milestone-5/outputFileStates/cache.properties.lock
./.gradle/1.0-milestone-5/taskArtifacts/cache.bin
./.gradle/1.0-milestone-5/taskArtifacts/cache.properties.lock
./build/reports/tests/com.sample.html
./build/reports/tests/com.sample.TestSampleClass.html
./build/reports/tests/index.html
./build/test-results/TEST-com.sample.TestSampleClass.xml
./build/tmp/jar/MANIFEST.MF
./one/build/tmp/jar/MANIFEST.MF
we can see from the output that even though we didn’t change anything between the calls to ‘build’, the ‘test’ task and subsequent check and build tasks are not marked as up to date. This remains the case for an arbitrary number of executions.
The last find command shows the files which were changed during the last build (I did a touch on file ‘stamp’ right before the previous gradle execution). The MANIFEST.MF files are created due to an issue I described in a previous post on these forums so we can ignore those for now. What is interesting is that the test results and reports are regenerated every execution.
Excerpt from the debug log:
... 14:13:48.207 [INFO] [org.gradle.api.internal.changedetection.DefaultTaskArtifactStateRepository] Executing task ':one:test' due to: Output file /Users/mbjarland/tmp/uptodatetest/build/reports/tests/com.sample.TestSampleClass.html for task ':one:test' has changed. Output file /Users/mbjarland/tmp/uptodatetest/build/reports/tests/index.html for task ':one:test' has changed. Output file /Users/mbjarland/tmp/uptodatetest/build/reports/tests/com.sample.html for task ':one:test' has changed. 14:13:48.208 [DEBUG] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] task ':one:test' is not up-to-date ...
so the log tells us that the files have changed and we need to re-run the test task. Well the files have changed because…err…the test task itself created the files during the previous run?
I did a quick attempt at trying to figure out why we get this behavior but couldn’t really come to any conclusive explanation. Yet. I’ll keep digging.
Perhaps this is the root project stepping on the sub-projects toes in some way? In either case, it would be nice to be able to combine aggregated test results/reports with a working up to date management. Re-running the tests every time is not an option as test executions can potentially take a long time.
Or perhaps there is a better recommended way of aggregating test results?
Any help much appreciated.