Michal Kordas Michal Kordas - 3 months ago 17
Groovy Question

Get list of Gradle tasks in type-safe way

I need to configure all tasks of type

FindBugs
with some custom configuration.

Right now I'm doing it as follows:

[findbugsMain as FindBugs, findbugsTest as FindBugs].each {
... // 'it' has now inferred 'FindBugs' type
}


However, I'm limited to the tasks I explicitly know and I need to perform nasty casts.

Is it possible to get list of all tasks of some particular type in some type-safe or compile-static friendly manner?

Answer

You can do it by:

tasks.withType(FindBugs)