In Gradle we can create dependencies between tasks. But we can also exclude certain tasks from those dependencies. We use the command-line option -x or --exclude-task and specify the name of task we don't want to execute. Any dependencies of this task are also excluded from execution. Unless another task depends on the same task and is executed. Let's see how this works with an example:
00.
task copySources << {
01.
println
'Copy sources.'
02.
}
03.
04.
task copyResources(dependsOn: copySources) << {
05.
println
'Copy resources.'
06.
}
07.
08.
task jar(dependsOn: [copySources, copyResources]) << {
09.
println
'Create JAR.'
10.
}
11.
12.
task deploy(dependsOn: [copySources, jar]) << {
13.
println
'Deploy it.'
14.
}
We execute the deploy task:
$ gradle -q deploy
Copy sources.
Copy resources.
Create JAR.
Deploy it.
Now we exclude the jar task. Notice how the copySources task is still executed because of the dependency in the deploy task:
$ gradle -q deploy -x jar
Copy sources.
Deploy it.