235

./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

  1. list all the tasks in all plugins with gradle
  2. list the tasks and what tasks they depend on (sort of like maven's dependency:tree but for tasks)
4
  • 4
    It's alarming that this isn't built in. Commented Sep 8, 2022 at 18:17
  • 6
    Its 2022, why is this not a part of Gradle? Commented Sep 21, 2022 at 11:28
  • 3
    its 2023, i've yet to find out if Gradle has added this now lmao Commented Apr 5, 2024 at 8:52
  • The answer from @marko-vranjkovic seems to be the most accurate answer at this point in time Commented Aug 15, 2024 at 14:36

11 Answers 11

251

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

Sign up to request clarification or add additional context in comments.

3 Comments

This doesn't list a task tree or task dependencies, it just lists which tasks would have been executed.
@bcampolo Whats the difference?
@kiltek this suggestion just says things like :analytics:preBuild SKIPPED, but it won't tell me why Gradle thought it should even bother with :analytics:preBuild. What was it that depended on :analytics:preBuild so that it had to be considered for execution?
109

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.

4 Comments

it doesn't seem to list a task for downloading dependencies from the web anywhere??? Running the task eclipse clearly download stuff but not sure where that dependency is...no way to overload it?
the action of downloading resources is not binded to a dedicated task. Dependencies in gradle are added to Configurations. As soon as you (in your own task implementation) or gradle (in its own provided tasks) references the files of this configuration, the resolving mechanism is triggered.
This doesn't list the dependencies, at least with Gradle 1.5 or 1.7. Is it that it did once do that, or is this an incomplete answer?
Works for gradle older than 3.3 only. There was a change in task reporting that removed this output.
96

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

5 Comments

For a cleaner output, use --no-repeat. Source: github.com/dorongold/gradle-task-tree
This doesnt work in 6.8+
@elect That issue was resolved. The newest version of the plugin works with 6.8+.
I can confirm that this worked for me (Gradle 4.8.1 with plugin version 1.5). Now I just need to complain why core gradle doesn't provide something like this.
gradle :build taskTree in case you are confused by the empty output.
59

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

3 Comments

This looks a little like a graph, but it's really just what each task depends on. It's a list of nodes with the parents of each node. So if your graph looks like A <- B <- (C and D), this will show you B-A, C-B, D-B. It still helps some!
It should be a graph, but rendering a graph is non-trivial. The output of the above code just lists the immediate dependencies of a task.
taskGraph.allTasks does not contain implicit dependencies. Any idea about that?
21

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.

4 Comments

Could you add the required repository code?
It's in the Gradle Plugin Portal, no extra repository information required. @SridharSarnobat
Hmmm, I guess my project's repo settings are restricting plugins to whatever my team has uploaded. Thanks.
It might be that you need to add gradlePluginPortal() under pluginManagement { repositories { ... }} in your settings.gradle. This is normally the default, but if there is another entry, such as your internal repository, it would overwrite that default. @SridharSarnobat
17

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

  1. gradle-visteg plugin: The generated file can be post-processed via Graphviz dot utility.

  2. 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.

1 Comment

The report does not contain any information about the dependencies between tasks. It just lists sequentially all tasks that were executed during the build.
8

You can programmatically access the task graph to inspect it within the build script using Gradle.getTaskGraph()

1 Comment

gradle.getTaskGraph() does only show you the tasks that will be executed in your current gradle build AND this taskGraph is only available at execution phase.
4

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)}
    }
}

Comments

2

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.

Comments

0

You can also add the following plugin for your local environment build.gradle, https://github.com/dorongold/gradle-task-tree

1 Comment

Note this requires dot to be installed
0

If plugins don't work for you, you can use this gist in your build.gradle

https://gist.github.com/jrodbx/046b66618c558ca9002a825629d59cde

1 Comment

Doesn't work with gradle 6.8.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.