What's the best way to find transitive *task* dependencies?

I’ve subverted the android plugin to build UI automator tests. To do this I only need the dexDebug and dexRelease tasks. I’d like to disable most of the rest of the tasks created by the android plugin. Something like

gradle.taskGraph.whenReady {
    (trasitiveDeps('installDebug').removeAll(transitiveDeps('dexDebug')).each() { it.enabled = false }

Writing transitiveDeps seems like it should be simple, but so far I don’t see it…

Transitive deps would look like:

Set<? extends Task> transitiveDeps(Task task) {
  (transitiveDeps(installDebug) - transitiveDeps(dexDebug))*.enabled = false

That’s what I was hoping… but unfortunately getDependencies doesn’t include transitive dependencies:

gradle.taskGraph.whenReady {
    def dex = tasks['dexDebug']
    println dex.taskDependencies.getDependencies(dex).dump()
    def compile = tasks['compileDebug']
    println compile.taskDependencies.getDependencies(compile).dump()


<java.util.LinkedHashSet@204f9c6d map=[task ':mail:uitest:compileDebug':java.lang.Object@782afee5]>
<java.util.LinkedHashSet@5224d289 map=[task ':mail:uitest:generateDebugSources':java.lang.Object@782afee5]>

Ah right, I should have read more closely.

There’s no public API to do what you need unfortunately. You’ll need to roll your own.

I ended up with:

Set<? extends Task> transitiveDeps(Set<? extends Task> tasks) {
   tasks + tasks.collect{ transitiveDeps(it.taskDependencies.getDependencies(it)) }.flatten()