Excluding tasks from execution

In this post of Gradle, I will show how to exclude a particular task from execution.

Below is the gradle script with three tasks


task task1 {
    doFirst {
        println 'I am task1'

task task2 {
    doFirst {
        println 'I am task2'

task task3 {
    doFirst {
        println 'I am task3'

In the above example I will exclude task3 from execution.

Open the command line and go to the folder containing the build.gradle.

Run the below code

gradle task1 task2 -x task3

We exclude task3 from execution using -x or –exclude-task

The gradle build will search for build.gradle file in the current folder and execute the mentioned tasks in the order they are listed in the argument except task3.

If you want to exclude multiple task say task2 and task3 from execution, type the below code in the command line

gradle task1 task2 -x task2 -x task3

Below is the output where only task3 is excluded from execution


E:\Projects\GradleConcepts\package3>gradle task1 task2 -x task3

Task :task1
I am task1

Task :task2
I am task2

2 actionable tasks: 2 executed


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s