Skip to content

Instantly share code, notes, and snippets.

@ldaley
Created December 6, 2013 21:58
Show Gist options
  • Save ldaley/7832804 to your computer and use it in GitHub Desktop.
Save ldaley/7832804 to your computer and use it in GitHub Desktop.
Transitive clean task in Gradle
apply plugin: "base"
tasks.all { task ->
task.ext.transitiveClean = {
tasks."clean${task.name.capitalize()}".dependsOn {
depsOf(task).flatten().collect { "clean${it.name.capitalize()}" }
}
}
}
def depsOf(Task task, allDeps = []) {
def thisDeps = task.taskDependencies.getDependencies(task)
allDeps.addAll(thisDeps)
thisDeps.each {
depsOf(it, allDeps)
}
allDeps
}
task a
task b
task c {
dependsOn a,b
transitiveClean()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment