What does Gradle 'build' task include exactly
Starting with version 4.0 you have to run gradle build --console=plain
to see the complete list of task dependencies.
If you use java-base
plugin then the dependencies are:
$ gradle build --console=plain
:assemble
:check
:build
If you use java
(which automatically applies java-base
) then the dependencies are:
$ gradle build --console=plain
:compileJava
:processResources
:classes
:jar
:assemble
:compileTestJava
:processTestResources
:testClasses
:test
:check
:build
In order to see the exact chain of dependencies shown in the pictures above I used a little Perl helper that can be run inside of a Gradle project. It produces a dot string describing dependency graph:
#/bin/perl
use strict;
my @deps;
my %tasks;
getDeps($ARGV[0]);
printDot();
sub getDeps {
my $task = shift;
$tasks{$task} = "";
chomp(my @subtasks = `gradle $task`);
@subtasks = grep { $_ =~ "^:" } @subtasks;
pop @subtasks;
foreach(@subtasks) {
my ($s) = $_ =~ "^:(.*) ";
push @deps, "$task -> $s;";
if(!defined $tasks{$s}) {getDeps($s)}
}
}
sub printDot {
my $dot = "digraph main {\n";
if(@deps>1) {
foreach(@deps) {$dot .= "$_\n"}
} else {
$dot .= "$ARGV[0];\n";
}
print $dot . "}";
}
Then run the following to turn the output into a PNG image:
$ t=build; perl dependencies.pl $t | tred | dot -T png > $t.png
or ASCII text:
$ t=build; perl dependencies.pl $t | tred | graph-easy > $t.txt
From the Gradle Java plugin docs
It's dependencies are the check & assemble task which you can see have their own dependencies
You can use the Gradle Task Tree Plugin to see the task dependencies
eg:
plugins {
id "com.dorongold.task-tree" version "1.3.1"
}
Then run
gradle build taskTree
Output
:build
+--- :assemble
| \--- :jar
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :check
\--- :test
+--- :classes
| +--- :compileJava
| \--- :processResources
\--- :testClasses
+--- :compileTestJava
| \--- :classes
| +--- :compileJava
| \--- :processResources
\--- :processTestResources