215

./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)
Gulzar
  • 23,452
  • 27
  • 113
  • 201
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212

11 Answers11

228

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

Marko Vranjkovic
  • 6,481
  • 7
  • 49
  • 68
  • 15
    This doesn't list a task tree or task dependencies, it just lists which tasks would have been executed. – bcampolo Oct 24 '19 at 17:17
  • 5
    @bcampolo Whats the difference? – kiltek Jul 02 '20 at 12:03
  • 5
    @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? – Johan Walles Jun 15 '22 at 08:41
107

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.

M. Justin
  • 14,487
  • 7
  • 91
  • 130
Rene Groeschke
  • 27,999
  • 10
  • 69
  • 78
  • 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? – Dean Hiller Jun 20 '12 at 18:30
  • 2
    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. – Rene Groeschke Jun 20 '12 at 20:50
  • 67
    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? – Tom Anderson Aug 16 '13 at 16:32
  • 15
    Works for gradle older than 3.3 only. There was a change in [task reporting](https://docs.gradle.org/3.3/release-notes.html#improved-performance-of-tasks-report) that removed this output. – Radim Sep 12 '17 at 08:25
85

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
Adam Burley
  • 5,551
  • 4
  • 51
  • 72
Oleksandr
  • 6,226
  • 1
  • 46
  • 54
51

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
Thomas Keller
  • 5,933
  • 6
  • 48
  • 80
cstroe
  • 3,740
  • 3
  • 27
  • 16
  • 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! – Noumenon Dec 20 '19 at 01:36
  • 1
    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. – cstroe Jul 10 '20 at 15:08
  • `taskGraph.allTasks` does not contain implicit dependencies. Any idea about that? – SMUsamaShah Mar 09 '22 at 18:14
20

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.

barfuin
  • 16,865
  • 10
  • 85
  • 132
  • Could you add the required repository code? – Sridhar Sarnobat Apr 02 '21 at 23:09
  • It's in the Gradle Plugin Portal, no extra repository information required. @SridharSarnobat – barfuin Apr 03 '21 at 12:34
  • Hmmm, I guess my project's repo settings are restricting plugins to whatever my team has uploaded. Thanks. – Sridhar Sarnobat Apr 03 '21 at 22:11
  • 1
    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 – barfuin Nov 09 '21 at 12:14
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.

AKS
  • 16,482
  • 43
  • 166
  • 258
  • 18
    The report does not contain any information about the dependencies between tasks. It just lists sequentially all tasks that were executed during the build. – rwitzel Mar 29 '15 at 09:51
8

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

Dylan Bijnagte
  • 1,326
  • 9
  • 17
  • 6
    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. – Rene Groeschke Jun 20 '12 at 20:56
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)}
    }
}
nimrodm
  • 23,081
  • 7
  • 58
  • 59
3

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.

Community
  • 1
  • 1
Dean Hiller
  • 19,235
  • 25
  • 129
  • 212
0

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

0

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

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

SMUsamaShah
  • 7,677
  • 22
  • 88
  • 131