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


(Mark Zeren) #1

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…


(Luke Daley) #2

Transitive deps would look like:

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

(Mark Zeren) #3

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()
}

yields

<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]>

(Luke Daley) #4

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.


(Mark Zeren) #5

I ended up with:

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