Search code examples
gradledependenciestask

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


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


Solution

  • 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.