Gianfranco Monzon
05/19/2022, 1:34 AMtasks.matching { it.name.contains(specificName) }
.configureEach { it.enabled = false }
It works, but it makes all tasks eagerly configured just to find out their name.Chris Lee
05/19/2022, 1:44 AMtasks.withType<Task>().configureEach {
enabled = !name.contains("foo")
}
Chris Lee
05/19/2022, 1:47 AMtasks.withType<Task>().configureEach {
if( name.contains(specificName)) {
enabled = false
}
}
Gianfranco Monzon
05/19/2022, 2:02 AMtasks.withType<Task>.configureEach
vs tasks.matching
? From outside, it seems like they are doing the same amount of work 😅Chris Lee
05/19/2022, 2:04 AMGianfranco Monzon
05/19/2022, 2:06 AMChris Lee
05/19/2022, 2:08 AMtasks.configureEach {
if( name.contains(specificName)) {
enabled = false
}
}
…calling configureEach on all tasks isn’t often used, but is appropriate in this case. Skips matching the type of each task (which will be a Task anyhow).Chris Lee
05/19/2022, 2:18 AMfun TaskCollection<Task>.lazyMatch(
predicate: (Task).() -> Boolean,
action: Action<Task>
) {
configureEach {
if (predicate(this)) {
action.execute(this)
}
}
}
tasks.lazyMatch({ name.contains("foo") }) {
enabled = false
}