Is there a way to list task dependencies in Gradle?

后端 未结 10 1022
逝去的感伤
逝去的感伤 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:15

    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 {
        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
    

提交回复
热议问题