What is the interplay between mustRunAfter and dependsOn?

When taskA “dependsOn” taskB and taskA “mustRunAfter” taskC, will taskB also run after taskC? My experiments say yes, but wanted to make sure.

task taskA << { println "Running task A" }

task taskB << {
println “Running task B”
}

task taskC << {
println “Running task C”
}

taskA.dependsOn taskB
taskA.mustRunAfter taskC

dohenry@ubuntu-1404-donhenry:~/metabuild$ gradlew -m taskC taskA
:taskC SKIPPED
:taskB SKIPPED
:taskA SKIPPED

BUILD SUCCESSFUL

There is no relationship between taskB and taskC here so their execution order is effectively whatever Gradle chooses. If you require that taskB should run after taskC then you should use a dependency or task ordering relationship to ensure that is the case.

Thanks, though this will be difficult to handle in my situation. I think it makes more sense for me to invoke gradlew twice to force taskA and its dependencies to be after taskC.

gradlew taskC gradlew taskA

I’m not sure how running two separate builds makes more sense than simply adding a task ordering relationship between the relevant tasks. Why can you not simply say that taskA.mustRunAfter taskC?

As you might expect, the actual situation I’m dealing with is more complicated. I can have up to six tasks that need to be ordered, and the actual number of tasks involved can change from one circumstance to another.

I was opposed to specifying the task order explicitly within the build.gradle file because it would seem to require a lot of ad hoc conditional code, but I think I can solve this with a few dependsOn’s in the afterevaluate block. I think the addition of this code balances off with a much simpler command line - most of the tasks will now be pulled in via dependencies. I’ll post the code once I get it working.