Gradle Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 18: Line 18:
A build is a Gradle execution. Each build starts with instantiation of a [[Gradle_Settings|Settings]] and [[Org.gradle.api.invocation.Gradle|Gradle]] instance, then of at least one [[Gradle Project#Overview|project]], which in turn contains [[Gradle Task#Overview|tasks]], and it can be configured and controlled with [[Gradle Runtime and Project Configuration#Overview|properties]]. Depending on the specific of the build, other [https://docs.gradle.org/current/dsl/#N100CA Gradle core types] are instantiated as well. The lifecycle of a Gradle build consists in an [[#Build_Initialization_Phase|initialization]], [[#Build_Configuration_Phase|configuration]] and an [[#Build_Execution_Phase|execution phase]]. Code can be written to [[Gradle Reacting to Build Lifecycle Events|react to a build's lifecycle events]].
A build is a Gradle execution. Each build starts with instantiation of a [[Gradle_Settings|Settings]] and [[Org.gradle.api.invocation.Gradle|Gradle]] instance, then of at least one [[Gradle Project#Overview|project]], which in turn contains [[Gradle Task#Overview|tasks]], and it can be configured and controlled with [[Gradle Runtime and Project Configuration#Overview|properties]]. Depending on the specific of the build, other [https://docs.gradle.org/current/dsl/#N100CA Gradle core types] are instantiated as well. The lifecycle of a Gradle build consists in an [[#Build_Initialization_Phase|initialization]], [[#Build_Configuration_Phase|configuration]] and an [[#Build_Execution_Phase|execution phase]]. Code can be written to [[Gradle Reacting to Build Lifecycle Events|react to a build's lifecycle events]].


<span id='Build_Initialization_Phase'></span><span id='Initialization'></span>'''Initialization phase'''. In case of a simple project, Gradle creates the Project instance. For a multi-project build, and depending on which project is executed, Gradle figures out which of the project dependencies need to participate in the build. [[Gradle Extra Properties#Overview|Extra properties]] for [[Org.gradle.api.invocation.Gradle|Gradle]] and [[Gradle_Settings|Settings]] object instances can be declared at this phase. None of the build scripts is executed in this phase.
==<span id='Initialization'></span>Initialization Phase==
 
 
 
The build lifecycle starts with the initialization phase, when Gradle creates a [[Gradle_Settings_Script_and_Settings_Instance#Overview|Settings]] instance, then executes the [[Gradle_Settings_Script_and_Settings_Instance#Overview|settings script]], which updates the state of its [[Gradle_Settings_Script_and_Settings_Instance#Overview|Settings delegate]]. In this phase, Gradle determines which projects are going to take part in the build and creates a [[Gradle_Project_and_Build_Script#Overview|project representation]] for each of the projects, essentially defining the build's project hierarchy. The sub-projects are declared using the "include" or "includeFlat" Settings methods in  [[Gradle_Settings_Script_and_Settings_Instance#Overview|settings.gradle]].
 
<span id='Project_Instance_Creation'></span>The corresponding [[Gradle_Project_and_Build_Script#Overview|Project]] instances are created and arranged in the corresponding project hierarchy. Note that at the initialization phase, Project instances are not accessible from the settings script. Project data can be accessed via a [[Gradle_Settings_Script_and_Settings_Instance#ProjectDescriptor_-_Access_to_Projects_from_Settings|ProjectDescriptor]] interface instead.
 
 
In case of a simple project, Gradle creates the Project instance. For a multi-project build, and depending on which project is executed, Gradle figures out which of the project dependencies need to participate in the build. [[Gradle Extra Properties#Overview|Extra properties]] for [[Org.gradle.api.invocation.Gradle|Gradle]] and [[Gradle_Settings|Settings]] object instances can be declared at this phase. None of the build scripts is executed in this phase.


<span id='Build_Configuration_Phase'></span><span id='Configuration'></span>'''Configuration phase'''. The code declared in [[build.gradle]] is executed in order. Tasks are [[Gradle_Task#Task_Lifecycle|instantiated and configured]], by executing their [[Gradle_Task#Task_Configuration_Closure|configuration closures]]. Any configuration code is executed with every build of the project. Gradle constructs a task DAG. <font color=darkgray>The [[Gradle_Task#Incremental_Builds|incremental build]] features determines if any of the tasks in the model are required to run.</font>
<span id='Build_Configuration_Phase'></span><span id='Configuration'></span>'''Configuration phase'''. The code declared in [[build.gradle]] is executed in order. Tasks are [[Gradle_Task#Task_Lifecycle|instantiated and configured]], by executing their [[Gradle_Task#Task_Configuration_Closure|configuration closures]]. Any configuration code is executed with every build of the project. Gradle constructs a task DAG. <font color=darkgray>The [[Gradle_Task#Incremental_Builds|incremental build]] features determines if any of the tasks in the model are required to run.</font>

Revision as of 21:29, 11 October 2020

External

Internal

Overview

Gradle is a general-purpose build tool. It is primarily used to build Java and Groovy, but it can build other languages as well. The goal of a Gradle execution, also known as a Gradle build, is to execute a set of tasks, in sequence. Each build runs according to a well defined build lifecycle, during which Gradle instantiates a complex domain model of the project in memory: a Gradle instance, a Settings instance and the project itself.

Build Lifecycle

A build is a Gradle execution. Each build starts with instantiation of a Settings and Gradle instance, then of at least one project, which in turn contains tasks, and it can be configured and controlled with properties. Depending on the specific of the build, other Gradle core types are instantiated as well. The lifecycle of a Gradle build consists in an initialization, configuration and an execution phase. Code can be written to react to a build's lifecycle events.

Initialization Phase

The build lifecycle starts with the initialization phase, when Gradle creates a Settings instance, then executes the settings script, which updates the state of its Settings delegate. In this phase, Gradle determines which projects are going to take part in the build and creates a project representation for each of the projects, essentially defining the build's project hierarchy. The sub-projects are declared using the "include" or "includeFlat" Settings methods in settings.gradle.

The corresponding Project instances are created and arranged in the corresponding project hierarchy. Note that at the initialization phase, Project instances are not accessible from the settings script. Project data can be accessed via a ProjectDescriptor interface instead.


In case of a simple project, Gradle creates the Project instance. For a multi-project build, and depending on which project is executed, Gradle figures out which of the project dependencies need to participate in the build. Extra properties for Gradle and Settings object instances can be declared at this phase. None of the build scripts is executed in this phase.

Configuration phase. The code declared in build.gradle is executed in order. Tasks are instantiated and configured, by executing their configuration closures. Any configuration code is executed with every build of the project. Gradle constructs a task DAG. The incremental build features determines if any of the tasks in the model are required to run.

Execution phase. Task actions are executed in the correct order, as determined by their dependencies. Task considered up-to-date are skipped.

Convention over Configuration

Subjects

TO DEPLETE

Gradle Concepts TO DEPLETE