Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between mustRunAfter and shouldRunAfter in task ordering in Gradle?

Tags:

I have this doubt as to when and which one out of shouldRunAfter and mustRunAfter should be used while ordering tasks in gradle.

like image 410
Niharika Avatar asked Apr 22 '16 13:04

Niharika


People also ask

What does Gradle use to determine the order in which tasks can be?

Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle command and the current directory. Gradle then executes each of the selected tasks.

What are the default Gradle tasks?

Gradle allows you to define one or more default tasks that are executed if no other tasks are specified. defaultTasks 'clean', 'run' tasks. register('clean') { doLast { println 'Default Cleaning! ' } } tasks.


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.

like image 166
Opal Avatar answered Sep 20 '22 15:09

Opal