Sometimes we need to build our project without a particular task, like lint , test or findbugs . Other times we just want to improve our gradle build time by skipping long running tasks. There are several ways of doing that, like overriding those tasks using the onlyIf() method to attach a predicate to it,

task myTask {

doLast {

println 'hello world'

}

}



myTask.onlyIf { !project.hasProperty('skipMyTask') }

…or by using the StopExecutionException which will skip further executions and actions of that specific task,

myTask.doFirst {

// Skip this task as we are in an integration test

if (true) { throw new StopExecutionException() }

}

…or you may want just to disable the execution of a single one, but this won’t skip its dependencies or itself if it’s a dependency.

myTask.enabled = false

You can find more information right in the Gradle User Guide site about the above mentioned.

Anyway, all these options need to be written by coding them into your gradle files. Although that might be a good approach to follow in order to setup efficiently our gradle files,

What if we only want to skip a single task without modifying our gradle files?

The answer is by using the -x command-line option and providing the name of the task to exclude straight into the command console.

./gradlew build -x lint

And what if we want to skip more than one task?

./gradlew build -x checkstyle -x pmd -x findbugs -x lint -x test

Just chain, as much as you need, the -x command-line plus the name of the task.

You can also accomplish this same approach by code, for instance, if you want to improve your gradle build time for some specific flavours.

if (project.hasProperty("skipLint")) {

gradle.startParameter.excludedTaskNames += "lint"

}

Drop me a line on Twitter, or leave a comment if you have any question or any update.