Gradle generally determines task order itself, which is often fine, but sometimes you need task ordering.
Based on the the User Guide and other discussion here it appears there are two basic ways to order tasks:
- Using dependencies, i.e. taskB depends on taskA, so taskA will execute first.
- Adding a new parent task, and using mustRunAfter as a constraint to sequence the subtasks.
However there are some situations where both approaches seem troublesome.
Example 1: In in daily task run by some continuous build system, you might have a sequence:
setupTask1 setupTask2 build test sendReport
Now, you can actually script this sequence externally, by passing these tasks on the gradle command line, i.e.
gradle setupTask1 setupTask2 build test sendReport
But if you want to write (and document) this sequence in the build file itself (rather than externally), are you required to create a new task, then add four new ordering constraints?
Example 2: Now imagine we have
startServer1 startServer2 integrationTest tearDownServer2 tearDownServer1
In this case, we want sequencing, but also control over failures, since if integrationTest fails, you still want the teardown steps to occur. Then we not only need mustRunAfter, we also have to add finalizedBy. And do we add the finalizer on integrationTest? What about if we add more tests that need such a harness? What if we want tearDownServer1 to be sequenced relative to tearDownServer2?
In summary, sequencing seems very clumsy, at least to a Gradle novice. In some cases, it might be more elegant simply to sequence things directly in a more imperative way. Am I missing something? Is there a better approach here?