How do I use org.gradle.api.tasks.TaskDependency?

I want to get all tasks with dependency on given task to modify them (e.g. change compiler arguments of JavaCompile tasks, that depend on main compilation taks). I am trying to use TaskDependency:

compileTask.taskDependencies.getDependencies(compileTask)

but it fails (see http://pastebin.com/55Jj9gUT).

How do I do this right way?

By the way, I am using Gradle 2.1, the project, that produced trace above can be found at https://bitbucket.org/AlexanderR/android-apt. Please ask, if you need a self-contained snippet to reproduce.

One option might be to get the taskgraph and then filter the list using the ‘dependOn’ value for each task.

taskGraph.whenReady { graph -> graph.allTasks.findAll { ... }
}

Aren’t contents of Set, returned by getDependOn, ambiguous, same as parameters, passed to dependOn (e.g. can be either of Task, String, Callable etc.)? This is exactly what I am trying to avoid.

Screw my previous comment, I have got it to work by combining TaskDependency.getDependencies with taskGraph.whenReady. Thanks for your help.