Skip to content

Instantly share code, notes, and snippets.

@cies
Created May 31, 2023 10:02
Show Gist options
  • Save cies/378dfbbe4080fb69bcda43f3610956f8 to your computer and use it in GitHub Desktop.
Save cies/378dfbbe4080fb69bcda43f3610956f8 to your computer and use it in GitHub Desktop.
Make Gradle print its task plan
// This prints the dependencies of each task in the current execution graph
gradle.taskGraph.whenReady(
closureOf<TaskExecutionGraph> {
println("About to run ${allTasks.size} tasks: (use `-i` to see why tasks are skipped, use `--rerun-tasks` to prevent UP-TO-DATE checks)")
allTasks.forEachIndexed { i, task ->
val dependenciesString =
if (task.dependsOn.isEmpty()) {
""
} else {
task.dependsOn.joinToString(", ", " (depends on ", ")") { dependency ->
dependency.toString().let {
if (it.startsWith("provider")) {
it.split("'")[1]
} else if (it.contains(" dirs")) {
"[$it]"
} else {
":${it.removePrefix(":")}"
}
}
}
}
println("${(i + 1).toString().padStart(5)}. :${task.name}$dependenciesString")
}
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment