Created
December 6, 2013 21:58
-
-
Save ldaley/7832804 to your computer and use it in GitHub Desktop.
Transitive clean task in Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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