Is there a way to list task dependencies in Gradle?

后端 未结 10 977
逝去的感伤
逝去的感伤 2020-12-07 10:33

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

相关标签:
10条回答
  • 2020-12-07 11:25

    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.

    0 讨论(0)
  • 2020-12-07 11:29

    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.

    0 讨论(0)
  • 2020-12-07 11:32

    You can try com.dorongold.task-tree plugin 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
    
    0 讨论(0)
  • 2020-12-07 11:32

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

    0 讨论(0)
提交回复
热议问题