Apply same configurations to different tasks

2019-08-13 01:38发布

问题:

For example I've got two closures in subprojects configuration (for example task1 - task2)

subprojects { 
    task1 {
        config 1
        config 2
    }
    task2 {
        config 1
        config 2
    }
}

How to apply same configuration for both tasks at once?

I was trying to do something like:

task1, task2 { 
    config 1
    config 2
}

or:

task2 {
    task1
}

However it does not work. How to do it correct if it's possible?

回答1:

Please try:

[task1, task2].each { t ->
   configure(t) {
      config1
      config2
   }
}


标签: groovy gradle