I have this doubt as to when and which one out of shouldRunAfter
and mustRunAfter
should be used while ordering tasks in gradle.
1 Answers
It's all documented well, please have a look here. Especially:
When you use the “must run after” ordering rule you specify that taskB must always run after taskA, whenever both taskA and taskB will be run. This is expressed as taskB.mustRunAfter(taskA). The “should run after” ordering rule is similar but less strict as it will be ignored in two situations. Firstly if using that rule introduces an ordering cycle. Secondly when using parallel execution and all dependencies of a task have been satisfied apart from the “should run after” task, then this task will be run regardless of whether its “should run after” dependencies have been run or not. You should use “should run after” where the ordering is helpful but not strictly required.
EDIT I also encourage you to read this post.

- 81,889
- 28
- 189
- 210
-
Thanks for the reply. Actually I read that earlier but the statement "Secondly when using parallel execution and all dependencies of a task have been satisfied apart from the “should run after” task, then this task will be run regardless of whether its “should run after” dependencies have been run or not" was little unclear. What all I understood by this is, ordering is strict in "mustRunAfter" whereas it's not always true for "shouldRunAfter". I am a newbie in Gradle, please correct me if I got it all wrong. – Niharika Apr 23 '16 at 17:47
-
@Niharika, you're right. `mustRunAfter` is for strict ordering, `shouldRunAfter` may not be obeyed during parallel execution. If you found my answer and clarification helpful, please accept the answer. – Opal Apr 25 '16 at 07:18