Home > Software design >  Is there a way to configure multiple gradle tasks at once?
Is there a way to configure multiple gradle tasks at once?

Time:10-10

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.)

CodePudding user response:

You can do

['a', 'b', 'c'].each {
   tasks.named(it).configure {
      dependsOn 'customTask'
   } 
}
  • Related