How to run tasks in a specific order (run uploadArchives after all sub projects tests are successful)

I have a multi module project and I would like to add a task to the root of the project which can be run by the CI but I also would like to specify the order in which tasks are run.

For instance, first I would like to run the tests for every sub project and when the tests are all OK I would like to run the uploadArchives task on all sub projects. The CI can then execute ‘gradle ci’ and have everything build and uploaded.

I tried adding dependencies (uploadArchives dependsOn test), this causes every sub project to first execute test and the uploadArchives tasks. This means if the test of subproject fails, the archives of all previous sub projects are already uploaded.

Is there a way to tell gradle to only execute uploadArchives on all sub projects after all the tests of the sub projects are successful? I would like to have something generic so I can put it in a plugin and use it for multiple projects.

Thanks.

The easy solution is to call Gradle with ‘gradle build uploadArchives’, or simulate the same by manipulating ‘gradle.startParameter.taskNames’. Unfortunately, I think this doesn’t work when running with ‘–parallel’.

It should also be possible to implement this using ‘Task#mustRunAfter’, but I can’t tell offhand how exactly this would work.

OK, I’ll go for the easy solution. Thanks.