Reputation: 20200
./gradle tasks
lists "some" of the tasks. Looking at
http://gradle.org/docs/current/userguide/java_plugin.html there are hidden ones not listed. Also, other plugins will not have such a nice pretty graph of the dependencies between tasks.
Is there a way to
dependency:tree
but for tasks)Upvotes: 232
Views: 134380
Reputation: 6356
You can try com.dorongold.task-tree plugin:
plugins {
id "com.dorongold.task-tree" version "2.1.1"
}
with simple usage:
gradle <task 1>...<task N> taskTree
Example result from the readme:
gradle build taskTree
:build
+--- :assemble
| \--- :jar
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :check
\--- :test
+--- :classes
| +--- :compileJava
| \--- :processResources
\--- :testClasses
+--- :compileTestJava
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :processTestResources
Upvotes: 93
Reputation: 7890
If plugins don't work for you, you can use this gist in your build.gradle
https://gist.github.com/jrodbx/046b66618c558ca9002a825629d59cde
Upvotes: 0
Reputation: 28653
Prior to Gradle 3.3, you could use the --all
flag to get a more detailed listing of the available tasks and the task dependencies:
gradle tasks --all
The dependency reporting was removed from this task as of Gradle 3.3 for performance reasons. This change and its rationale was documented in the Gradle 3.3 release notes.
Upvotes: 110
Reputation: 17484
There's a new plugin for this:
plugins {
id 'org.barfuin.gradle.taskinfo' version '1.0.1'
}
Then you can type:
./gradlew tiTree assemble
and get something like this:
:assemble (org.gradle.api.DefaultTask)
+--- :jar (org.gradle.api.tasks.bundling.Jar)
| `--- :classes (org.gradle.api.DefaultTask)
| +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)
| `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)
+--- :javadocJar (org.gradle.api.tasks.bundling.Jar)
| `--- :javadoc (org.gradle.api.tasks.javadoc.Javadoc)
| `--- :classes (org.gradle.api.DefaultTask)
| +--- :compileJava (org.gradle.api.tasks.compile.JavaCompile)
| `--- :processResources (org.gradle.language.jvm.tasks.ProcessResources)
`--- :sourcesJar (org.gradle.api.tasks.bundling.Jar)
The plugin can also show the order in which tasks will be executed:
In order to execute task ':assemble', the following tasks would be executed in this order:
1. :compileJava (org.gradle.api.tasks.compile.JavaCompile)
2. :processResources (org.gradle.language.jvm.tasks.ProcessResources)
3. :classes (org.gradle.api.DefaultTask)
4. :jar (org.gradle.api.tasks.bundling.Jar)
5. :javadoc (org.gradle.api.tasks.javadoc.Javadoc)
6. :javadocJar (org.gradle.api.tasks.bundling.Jar)
7. :sourcesJar (org.gradle.api.tasks.bundling.Jar)
8. :assemble (org.gradle.api.DefaultTask)
More info in the plugin's docs.
Full disclosure: I am the author of gradle-taskinfo.
Upvotes: 21
Reputation: 4236
You can stick this into your build.gradle
:
gradle.taskGraph.whenReady {taskGraph ->
println "Found task graph: " + taskGraph
println "Found " + taskGraph.allTasks.size() + " tasks."
taskGraph.allTasks.forEach { task ->
println task
task.dependsOn.forEach { dep ->
println " - " + dep
}
}
}
or this into your build.gradle.kts
:
gradle.taskGraph.whenReady(closureOf<TaskExecutionGraph> {
println("Found task graph: $this")
println("Found " + allTasks.size + " tasks.")
allTasks.forEach { task ->
println(task)
task.dependsOn.forEach { dep ->
println(" - $dep")
}
}
})
Then run your task with gradle:
./gradlew build
And you should see this:
Found task graph: org.gradle.execution.taskgraph.DefaultTaskGraphExecuter@36eb780c
Found 19 tasks.
task ':compileJava'
- task 'compileJava' input files
task ':compileScala'
- task 'compileScala' input files
- compileJava
task ':processResources'
- task 'processResources' input files
task ':classes'
- org.gradle.api.internal.tasks.DefaultTaskDependency@287a7782
- task 'classes' input files
- compileJava
- dirs
- compileScala
- processResources
task ':jar'
- task 'jar' input files
task ':assemble'
- task 'assemble' input files
- org.gradle.api.internal.artifacts.DefaultPublishArtifactSet$ArtifactsTaskDependency@5bad9616
task ':compileTestJava'
- task 'compileTestJava' input files
task ':compileTestScala'
- task 'compileTestScala' input files
- compileTestJava
task ':processTestResources'
- task 'processTestResources' input files
task ':testClasses'
- processTestResources
- task 'testClasses' input files
- compileTestScala
- org.gradle.api.internal.tasks.DefaultTaskDependency@42c1fa08
- compileTestJava
- dirs
task ':compileIntegrationTestJava'
- task 'compileIntegrationTestJava' input files
task ':compileIntegrationTestScala'
- task 'compileIntegrationTestScala' input files
- compileIntegrationTestJava
task ':processIntegrationTestResources'
- task 'processIntegrationTestResources' input files
task ':integrationTestClasses'
- processIntegrationTestResources
- compileIntegrationTestJava
- org.gradle.api.internal.tasks.DefaultTaskDependency@7c8aa0fe
- compileIntegrationTestScala
- dirs
- task 'integrationTestClasses' input files
task ':composeUp'
- task 'composeUp' input files
task ':integrationTest'
- task ':composeUp'
- task 'integrationTest' input files
task ':test'
- task 'test' input files
task ':check'
- task 'check' input files
- task ':test'
- task ':integrationTest'
task ':build'
- task 'build' input files
- check
- assemble
Upvotes: 57
Reputation: 23809
Following the answer by cstroe, the following also prints the input and output files of each Gradle task. This is useful since dependencies are sometimes defined by input/output relations. I.e., if task B uses the outputs of task A, cstroe's answer won't show you the dependency. The following is very primitive but does show the list of input and output files for each task:
gradle.taskGraph.whenReady {taskGraph ->
println "Found task graph: " + taskGraph
println "Found " + taskGraph.allTasks.size() + " tasks."
taskGraph.allTasks.forEach { task ->
println()
println("----- " + task + " -----")
println("depends on tasks: " + task.dependsOn)
println("inputs: ")
task.inputs.getFiles().getFiles().collect { f -> println(" - " + f)}
println("outputs: ")
task.outputs.getFiles().getFiles().collect { f -> println(" + " + f)}
}
}
Upvotes: 4
Reputation: 17326
gradle task tree can be visualized by gradle tasks --all
or try the following plugins:
Graphs Gradle and Talaiot: Look into this: https://proandroiddev.com/graphs-gradle-and-talaiot-b0c02c50d2b1 blog as it lists graphically viewing tasks and dependencies. This uses free open Graphviz tool Gephi (https://gephi.org/features/)
gradle-task-tree: https://github.com/dorongold/gradle-task-tree and
gradle-visteg: https://github.com/mmalohlava/gradle-visteg
gradle-visteg plugin: The generated file can be post-processed via Graphviz dot
utility.
For example, png image is produced as follows:
cd build/reports/; dot -Tpng ./visteg.dot -o ./visteg.dot.png
For more information, please visit Graphviz home page.
Whatever tasks are actually used to run a task (for ex: build
) can be viewed in nice HTML page using --profile
option
gradle --profile clean build
Once this is complete, go to build/reports/profile folder and browse the .html file. You'll see dependencies resolution and other info with time it took in a nice html page.
Upvotes: 17
Reputation: 41
You can also add the following plugin for your local environment build.gradle, https://github.com/dorongold/gradle-task-tree
Upvotes: 0
Reputation: 6869
list the tasks and what tasks they depend on (sort of like maven's depenceny:tree but for tasks)
for this you can use --dry-run
(or -m
) option which lists tasks which are executed in order for particular command, but does not execute the command, e.g.
gradle assemble --dry-run
you can find more here
Upvotes: 251
Reputation: 20200
As your multiproject grows, the solution I marked as correct grows a bit unweildy and hard to read
gradle tasks --all
Instead, I have moved over to looking at a specific project making it much easier
gradlew :full-httpproxy:tasks --all
where 'full-httpproxy' is the name of my project(and directory as is typical).
I am however curious how to list tasks on the master/root project though and have an outstanding question here as well
How to list all tasks for the master project only in gradle?
as doing that doesn't seem possible right now.
Upvotes: 3
Reputation: 1356
You can programmatically access the task graph to inspect it within the build script using Gradle.getTaskGraph()
Upvotes: 8