The task graph

Before Gradle runs a task it builds the whole plan: every task the command needs, in an order that respects the dependencies, and nothing else. Two options show the plan without doing the work, and the plan is the best explanation of what a command really does.

--dry-run

settings.gradle

rootProject.name = 'shop'

build.gradle

plugins { id 'java' id 'application' } application { mainClass = 'com.example.App' }

src/main/java/com/example/App.java

package com.example; public final class App { public static void main(String[] args) { System.out.println("shop"); } }

--dry-run prints the plan and marks every task SKIPPED. Nothing is compiled and nothing is written:

gradle build --dry-run --console=plain --offline --no-daemon

:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:jar SKIPPED
:startScripts SKIPPED
:distTar SKIPPED
:distZip SKIPPED
:assemble SKIPPED
:compileTestJava SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:test SKIPPED
:check SKIPPED
:build SKIPPED

BUILD SUCCESSFUL in 13s

--info and the plan

--info runs the build and prints what it decided on the way. Among thousands of lines there is one that lists the plan as data:

gradle build --info --console=plain --offline --no-daemon 2>&1 | grep "Tasks to be executed"

Tasks to be executed: [task ':compileJava', task ':processResources', task ':classes', task ':jar', task ':startScripts', task ':distTar', task ':distZip', task ':assemble', task ':compileTestJava', task ':processTestResources', task ':testClasses', task ':test', task ':check', task ':build']

The same fourteen tasks as above, in the order they run, with the project path in front of each name. The list comes from the graph, not from the script: the application plugin added startScripts, distTar and distZip to assemble, and the java plugin added the three verification tasks.

Reading the graph

Related

Автор статьи: Arthur Isaev