Can I exclude tasks using a name pattern?


(ken.kousen) #1

In an Android project, there are lint tasks for every flavor, like lintFlavor1Release, lintFlavor2Release, etc, as well as lint.

I’d like to exclude all of them during a quick build. Normally I’d just run

./gradlew build -x lint

but that only excludes one of them. I could, in principle, specify all of them individually, but is there a way to put in some sort of wildcard or pattern instead?


(ken.kousen) #2

Here’s how I solved it in the build file:

gradle.taskGraph.whenReady { graph ->
    graph.allTasks.findAll { it.name ==~ /lint.*/ }*.enabled = false
}

I could also add a block like if (System.hasProperty(noLint)) to it and use the -P flag to set that property, but I’m not sure this is the best solution. Alternatives welcome.


(Eric Wendelin) #3

In my mind, it feels like a workaround to disable tasks and is preferable to construct a task that does what you want.

Something like:

task quickBuild {
    // Tasks you want to run, avoiding lint
    dependsOn(['assemble', 'dist'])
}

However, if that is not possible, introducing an opt-in flag using Project properties would be preferable (unless your intent is to forevermore disable all linting for everyone).