You mean task copyFalvor3 copies files whose name comes from android.productFlavors.flavor3.name, right?
If so, create List of flavors, and iterates it with creating tasks. This way doesn’t requires passing arguments.
[android.productFlavors.flavor1,
android.productFlavors.flavor2,
android.productFlavors.flavor3].collect {
it.name
}.eachWithIndex {flavorName, index ->
task "copyFlavor${index}"(type: Copy) {
from "${srcDir}/${flavorName}"
// and so on
}
}
And this should be defined inside any kind of task? or simply in the root script in the afterEvaluate maybe? Also, how to do it if the flavor names are: flavorBanana, flavorPeach, flavorApple?
[android.productFlavors.flavorBananas,
android.productFlavors.flavorPeach,
android.productFlavors.flavorApple].collect {
it
}.eachWithIndex {flavorName, index ->
task "copy${flavorName}"(type: Copy) {
from "${srcDir}/${flavorName}"
// and so on
}
}
android.productFlavors.collect {
it.name
}.eachWithIndex {flavorName, index ->
task "copy${flavorName}"(type: Copy) {
from "${srcDir}/${flavorName}"
// and so on
}
}