Reputation: 1559
I have the following snippet in a build.gradle
file for a project I work on:
tasks.named('test').configure {
dependsOn customTask
}
tasks.named('compileTestJava').configure {
dependsOn customTask
}
tasks.named('jar').configure {
dependsOn customTask
}
tasks.named('build').configure {
dependsOn customTask
}
It seems redundant to have to specify the the same configuration for 4 tasks separately. Is there a way to select and configure multiple tasks at once? Perhaps something like:
tasks.named('test', 'compileTestJava', 'jar', 'build').configure {
dependsOn customTask
}
(I tried this code, but it does not work.)
Upvotes: 2
Views: 1139
Reputation: 1
In the source code we have the method named(Spec<String> nameFilter)
. This is configuration avoidance API.
Example:
tasks.named { it in ['a', 'b', 'c'] }.configureEach {
dependsOn 'customTask'
}
Upvotes: 0
Reputation: 27984
You can do
['a', 'b', 'c'].each {
tasks.named(it).configure {
dependsOn 'customTask'
}
}
Upvotes: 3