51

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.

4 Answers 4

38

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 
Sign up to request clarification or add additional context in comments.

2 Comments

Up that plugin version to 1.3.1 if you want to fix the decorater error message as discussed here. Prefer this answer since it gives something reusable as well as an answer :)
This gives a great insight of the dependencies
22

From the Gradle Java plugin docs

build dependencies

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

Comments

16

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 

2 Comments

Thanks for detailed reply
I recommend gradle build --dry-run over gradle build --console=plain, since the dry run is designed to print the tasks that would have been output rather than actually running the tasks. (--dry-run documentation)
1

In short:

Compiles, tests and assembles the code into a JAR file

More info here:

You’ll use the gradle build task frequently. This task compiles, tests, and assembles the code into a JAR file. You can run it like this:

gradle build

After a few seconds, "BUILD SUCCESSFUL" indicates that the build has completed.

To see the results of the build effort, take a look in the build folder. Therein you’ll find several directories, including these three notable folders:

  • classes. The project’s compiled .class files.
  • reports. Reports produced by the build (such as test reports).
  • libs. Assembled project libraries (usually JAR and/or WAR files).

Gradle Tasks view of Eclipse / Spring Tool Suite

enter image description here

Sample dry-run:

gradlew build --dry-run
gradlew -m build (Same as above)

:compileJava SKIPPED
:processResources SKIPPED
:classes SKIPPED
:bootWarMainClassName SKIPPED
:bootWar SKIPPED
:bootStartScripts SKIPPED
:bootDistTar SKIPPED
:bootDistZip SKIPPED
:jar SKIPPED
:startScripts SKIPPED
:distTar SKIPPED
:distZip SKIPPED
:war SKIPPED
:assemble SKIPPED
:compileTestJava SKIPPED
:processTestResources SKIPPED
:testClasses SKIPPED
:test SKIPPED
:check SKIPPED
:build SKIPPED

BUILD SUCCESSFUL in 32s

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.