I have a multi project build and want a task that runs tests for each subproject and then, if all were successful, uploads them all.
What is the best way to do this?
I have a multi project build and want a task that runs tests for each subproject and then, if all were successful, uploads them all.
What is the best way to do this?
You could just add a dependency to the ‘test’ task to whichever task uploads your artifacts.
uploadArchives.dependsOn test
I should have mentioned that I had tried that without success.
Only the subprojects generate any artifacts. The top level gradle.build is roughly like this
subprojects {
apply plugin: ‘java’
uploadArchives {
repositories {
//…
}
}
} }
uploadArchives.dependsOn test
The output then included this :compileJava UP-TO-DATE :processResources UP-TO-DATE :classes UP-TO-DATE :jar UP-TO-DATE :compileTestJava UP-TO-DATE :processTestResources UP-TO-DATE :testClasses UP-TO-DATE :test UP-TO-DATE :uploadArchives <snipped: lots of upLoadArchive tasks for subprojects>
In other words ‘test’ was executed but only for the (empty) top level project. On the other hand ALL the uploadArchives tasks were run.
You’ll just have to apply the change to every subproject. Try placing this in your root project ‘build.gradle’.
subprojects {
uploadArchives.dependsOn test
}
While that ensures that each subproject is tested, it does not ensure that all tests are completed before ANY subproject is uploaded. In other words we get
a:test a:upload b:test b:upload
whereas what I want is
a:test b:test a:upload b:upload
What I particularly want to avoid is the case where ‘a’ is tested and uploaded, but b’s test fails (and the upload is then not done).
Oh I see. In that case every project’s ‘uploadArchives’ task will in turn need to depend on every other project’s ‘test’ task. This should acomplish that behavior.
subprojects {
uploadArchives.dependsOn {
rootProject.subprojects.collect {
it.tasks.getByName ‘test’
}
}
}
Thank you A bit brutal, but it does achieve the desired result.