Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does Gradle 'build' task include exactly

Tags:

java

gradle

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.

  • It comes from java-base plugin, right?
  • Running 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.

like image 387
LazerBanana Avatar asked Jun 02 '17 08:06

LazerBanana


People also ask

What are tasks in Gradle build?

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.

What is inside Gradle build?

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.

Does Gradle build run all tasks?

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.

What happens during Gradle build?

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.


3 Answers

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
like image 70
lance-java Avatar answered Oct 17 '22 11:10

lance-java


From the Gradle Java plugin docs

build dependencies

It's dependencies are the check & assemble task which you can see have their own dependencies

like image 45
Eduardo Avatar answered Oct 17 '22 09:10

Eduardo


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

enter image description here

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

enter image description here

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
like image 14
Johnny Baloney Avatar answered Oct 17 '22 09:10

Johnny Baloney