Skip to content

Instantly share code, notes, and snippets.

@kekru
Created February 16, 2021 20:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kekru/9ed32d9f0b2a70288b4dd122f96e4abd to your computer and use it in GitHub Desktop.
Save kekru/9ed32d9f0b2a70288b4dd122f96e4abd to your computer and use it in GitHub Desktop.
Gradle union task, execute in order

Gradle: Union wrapper task to execute subtasks in order

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment