Reputation: 133
I see this example of dynamic Gradle tasks on various sites:
4.times { counter ->
task "task$counter" << {
println "I'm task number $counter"
}
}
I would like to create dynamic tasks based on a list of strings such as:
def taskSuffixes = ["foo", "bar", "baz"]
taskSuffixes.each { it ->
task t_$it << {
println "My name is: $it"
}
}
However, that does not seem to work. Is this possible? If it is not possible, what would be a good alternative given that my list will be strings and I will eventually need those strings within the matching task?
Upvotes: 1
Views: 1500
Reputation: 171154
You need to put double quotes round your templated string
task "t_$it" << {
println "My name is: $it"
}
<<
was deprecated around Gradle 4, the new way is to use doLast
task "t_$it" {
doLast {
println "My name is: $it"
}
}
Upvotes: 3