Last active
September 8, 2022 18:29
-
-
Save jrodbx/046b66618c558ca9002a825629d59cde to your computer and use it in GitHub Desktop.
Graphviz visualization of a Gradle project's task graph
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gradle.taskGraph.whenReady { | |
println "rootProject: " + rootProject.name | |
println "childProjects: " + rootProject.childProjects | |
def dot = new File(rootProject.buildDir, 'project.dot') | |
dot.delete() | |
def command = "./gradlew " + gradle.startParameter.getTaskNames().join(" ") | |
println "command: " + command | |
dot << 'digraph {\n' | |
dot << " graph [label=\"${command}\\n \",labelloc=t,fontsize=30];\n" | |
dot << ' node [style=filled, fillcolor="#bbbbbb"];\n' | |
dot << ' rankdir=LR;\n\n' | |
gradle.taskGraph.allTasks.each { task -> | |
println "task: " + task.name + ", class: " + task.class.name | |
task.taskDependencies.getDependencies(task).each { dep -> | |
dot << " \"${dep.name}\" -> \"${task.name}\"" | |
dot << " [style=dotted]" | |
dot << '\n' | |
} | |
} | |
dot << '\n' | |
dot << '}\n' | |
def p = 'dot -Tpng -O project.dot'.execute([], rootProject.buildDir) | |
p.waitFor() | |
if (p.exitValue() != 0) { | |
throw new RuntimeException(p.errorStream.text) | |
} | |
println("Task graph created at ${dot.absolutePath}.png") | |
} | |
gradle.taskGraph.afterTask { task -> | |
println " inputs: " | |
task.inputs.files.each { println " " + it } | |
println " outputs: " | |
task.outputs.files.each { println " " + it} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Doesn't work with gradle 6.8.1