gradle Ordering tasks Ordering with the mustRunAfter method


task A << {
    println 'Hello from A'
task B << {
    println 'Hello from B'

B.mustRunAfter A

The 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 B

The 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