Skipping tasks
Sometimes, we want tasks to be excluded from a build. In certain circumstances, we just want to skip a task and continue executing other tasks. We can use several methods to skip tasks in Gradle.
Using onlyIf predicates
Every task has an onlyIf
method that accepts a closure as an argument. The result of the closure must be true
or false.
If the task must be skipped, the result of the closure must be false
, otherwise the task is executed. The task
object is passed as a parameter to the closure. Gradle evaluates the closure just before the task is executed.
The following build file will skip the longrunning
task, if the file is executed during weekdays, but will execute it during the weekend:
import static java.util.Calendar.* task longrunning ...
Get Gradle Effective Implementations Guide - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.