This is how to create a union tasks to execute subtasks in order
task A { doLast { println 'A' }}
task B { doLast { println 'B' }}
task C { doLast { println 'C' }}
task D { doLast { println 'D' }}
task unionTask {
def containedTasks = [A, B, C, D]
dependsOn containedTasks
placeTasksInOrder(containedTasks)
}
def placeTasksInOrder(List tasks) {
for (int i=0; i < tasks.size() -1; i++) {
def earlierTask = tasks.get(i)
def laterTask = tasks.get(i +1)
laterTask.mustRunAfter(earlierTask)
}
}
dependsOn causes the other tasks to run when unionTask is run and the helper function placeTasksInOrder places the tasks in order by calling mustRunAfter
See also Stackoverflow