Task Dependencies: Could not determine the dependencies of null

(Martin Jöhren) #1

I just played a bit with task dependencies and wanted to create a task which just prints all task dependencies into a dot file. So I started with something like

task taskDependencies << {
    allprojects.each { proj ->
        proj.tasks.each{ Task t ->
            println t.name + ": " + t.getClass()
            if(t.getTaskDependencies() != null && t.getTaskDependencies().getDependencies() != null && t.getTaskDependencies().getDependencies().size() > 0){
                t.getTaskDependencies().getDependencies().each{ d ->
d.getProject().name + ":" + d.name +"\n"

and after some tasks I got the error: “Could not determine the dependencies of null”. So I looked into the code and found that “getDependencies()” wants a Task as parameter. So I changed the line to “getDependencies(t)” and it worked fine. My question is now, why worked the code without the parameter for example for the task ‘assemble’ and throw an error for task ‘buildDependents’. Is it a correct behavior? Shouldn’t it just throw an exception for all tasks when the parameter is null? If you need the build.gradle file or more information, please let me know.

(Szczepan Faber) #2

There are various implementations of TaskDependency and perhaps some of those are lenient enough to accept null parameter. I think the contract is that you should pass a valid task as a parameter and this seems to work just fine :slight_smile: