What's the difference between mustRunAfter and dependsOn in Gradle?

Dan B. picture Dan B. · Feb 3, 2017 · Viewed 9.1k times · Source

Whether taskB mustRunAfter taskA, or taskB dependsOn taskA, it seems that taskA runs first, then taskB runs. What's the difference?

Answer

mkobit picture mkobit · Feb 4, 2017

For example:

tasks.create('a')

tasks.create('b').dependsOn('a')

tasks.create('c')

tasks.create('d').mustRunAfter('c')
  • dependsOn - sets task dependencies. Executing b here would require that a be executed first.
  • mustRunAfter - sets task ordering. Executing d does not require c. But, when both c and d are included, c will execute before d.