What's the difference between mustRunAfter and dependsOn in Gradle?
For example:
tasks.create('a')
tasks.create('b').dependsOn('a')
tasks.create('c')
tasks.create('d').mustRunAfter('c')
dependsOn
- sets task dependencies. Executingb
here would require thata
be executed first.mustRunAfter
- sets task ordering. Executingd
does not requirec
. But, when bothc
andd
are included,c
will execute befored
.
Sometimes they have the same effect. For example, if taskC dependsOn taskA and taskB, then it doesn't matter whether taskB dependsOn taskA or mustRunAfter it - when you run taskC, the order will be taskA, taskB, taskC.
But if taskC dependsOn taskB only, then there's a difference. If taskB dependsOn taskA, then it's the same as above - taskA, taskB, taskC. If taskB merely mustRunAfter taskA, then taskA doesn't run, and running taskC will run taskB, then taskC.
mustRunAfter really means if taskA runs at all, then taskB must run after it.