Ordering tasks
Remarks#
Please note that
mustRunAfterandshouldRunAfterare marked as “incubating” (as of Gradle 3.0) which means that these are experimental features and their behavior can be changed in future releases.
There are two ordering rules available:
mustRunAftershouldRunAfter
When you use the mustRunAfter ordering rule you specify that taskB must always run after taskA, whenever both taskA and taskB will be run.
The shouldRunAfter ordering rule is similar but less strict as it will be ignored in two situations:
- if using that rule introduces an ordering cycle.
- when using parallel execution and all dependencies of a task have been satisfied apart from the
shouldRunAftertask, then this task will be run regardless of whether itsshouldRunAfterdependencies have been run or not.
Ordering with the mustRunAfter method
task A << {
println 'Hello from A'
}
task B << {
println 'Hello from B'
}
B.mustRunAfter AThe B.mustRunAfter A line tells Gradle to run task after task specified as an argument.
And the output is:
> gradle -q B A
Hello from A
Hello from BThe ordering rule doesn’t introduce dependency between the A and the B tasks, but has an effect only when both tasks are scheduled for execution.
It means that we can execute tasks A and B independently.
The output is:
> gradle -q B
Hello from B