Not exactly a newb but am trying to dig a big deeper and understand a bit better ... just thought it might be a nice idea to do this.
Thanks to Opal I did this:
gradle.taskGraph.whenReady {taskGraph ->
println "Tasks"
taskGraph.getAllTasks().eachWithIndex{ task, n ->
println "${n + 1} $task"
task.dependsOn.eachWithIndex{ depObj, m ->
println " ${ m + 1 } $depObj"
}
}
}
Output for a Java build:
Tasks
1 task ':compileJava'
2 task ':processResources'
3 task ':classes'
1 compileJava
2 dirs
3 processResources
4 task ':jar'
5 task ':assemble'
1 org.gradle.api.internal.artifacts.DefaultPublishArtifactSet$ArtifactsTaskDependency@48db7705
6 task ':compileTestJava'
7 task ':processTestResources'
8 task ':testClasses'
1 processTestResources
2 dirs
3 compileTestJava
9 task ':test'
10 task ':check'
1 value: task ':test'
11 task ':build'
1 check
2 assemble
For me, as a Gradle neophyte (one up from a newb), this is great! Although it leaves me slightly puzzled:
1) "build" depends only on "check" and "assemble", and these have 1 dependency each, each with no dependencies. So how does it know to run all the other tasks (which obviously it has to)... I must be missing something.
2) what is dependency "dirs" and "org.gradle.api.internal.artifacts.DefaultPublishArtifactSet$ArtifactsTaskDependency@48db7705"? More importantly, where does these actually come from? getDependsOn() returns a Set<Object> so these may be something other than Tasks.
Plenty to investigate...
The gradle-taskinfo plugin probably does just what Opal describes in his answer.
I wrote it, so I might be biased, but I use it a lot and it works great for me. 😊
Maybe it saves you some time coding!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With