How to create dynamic tasks in Gradle?
You can create dynamic tasks with Gradle using Groovy. The power of Groovy can be used for more than defining what a task does.
You cannot create dynamic task in ant or maven.
4.times { counter ->
task "task$counter" << {
println "I am task number $counter"
}
}
|
Run command gradle tasks to see the task dynamically created:
java2novice$ gradle tasks
:tasks
Other tasks
-----------
task0
task1
task2
task3
To see all tasks and more detail, run with --all.
BUILD SUCCESSFUL
Total time: 2.985 secs
|
Gradle created 4 dynamic tasks here, the task names also dynamic. Run command gradle task2 to see the output:
java2novice$ gradle task2
:task2
I am task number 2
BUILD SUCCESSFUL
Total time: 1.711 secs
|
Reference: Gradle Documentation
|