I have searched on Gradle docs and on the stackoverflow and some other places but I can't find information about what is bundled in this task in depth, or I missed it, if so please point me to the direction.
java-base
plugin, right?gradle -q tasks
doesn't say much about it.build - Assembles and tests this project.
Running gradle help --task build
shows detailed info, ok - but it show where the task is used, in which groups is included, type of a task, and paths.
I have tried to track manually what does comes with it, and noticed, compile, test etc tasks.
I would like to know what exactly comes from Gradle build task, what are the task dependencies.
In Gradle, Task is a single unit of work that a build performs. These tasks can be compiling classes, creating a JAR, Generating Javadoc, and publishing some archives to a repository and more. It can be considered as a single atomic piece of work for a build process.
Every Gradle build is composed of at least one project (e.g. a library JAR, a Java application, a web application). Each project is made up of one or more tasks. A task represents some atomic piece of work that a build performs.
You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.
Build phasesDuring the initialization phase, Gradle determines which projects are going to take part in the build, and creates a Project instance for each of these projects. During this phase the project objects are configured. The build scripts of all projects which are part of the build are executed.
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
From the Gradle Java plugin docs
It's dependencies are the check & assemble task which you can see have their own dependencies
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With