Gradle Settings Script and Settings Instance: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 8: Line 8:


=Overview=
=Overview=
The settings.gradle file describes the build's project hierarchy. In the simplest case, there is no settings.gradle, and the build consists in just a single project, the root project. In more complex cases, various sub-project hierarchies can be specified. The file can also be used to add libraries to the build script classpath.
The configuration file is executed during the [[Gradle_Concepts#Build_Initialization_Phase|initialization phase]] and updates the state of the delegate [Settings] instance.
. For a single-project build, this file is optional, but required for [[Gradle_Concepts_ToDeplete#Multi-Project_Build|multi-project builds]]: the multi-project builds must have this file in the root project.
A bootstrap settings.gradle may be created automatically on project initialization with [[Gradle_Operations#Start_a_Project|gradle init]].
The subprojects are declared in the [[Gradle_Concepts_ToDeplete#Multi-Project_Build|root project]] settings.gradle with the "include" or "includeFlat" methods:
<syntaxhighlight lang='groovy'>
include 'subproject1', 'subproject2:subsubproject3'
</syntaxhighlight>
<syntaxhighlight lang='groovy'>
includeFlat 'subproject1', 'subproject2'
</syntaxhighlight>
The "include" method takes hierarchical project paths as arguments, while "includePath" expects a flat sibling structure. For more details about syntax, see [[Gradle_Concepts_ToDeplete#Hierarchical|Hierarchical Layout]] and [[Gradle_Concepts_ToDeplete#Flat|Flat Layout]].
The property access and method calls within the settings file is delegated to a [https://docs.gradle.org/4.7/dsl/org.gradle.api.initialization.Settings.html Settings] instance.
=Resolution=
* Look at a directory called "master" on the same nesting level as the current directory.
* If not found, search parent directories.
* If not found, the build executes as a single project build.
* If found, Gradle checks if the current project is part of multi-project hierarchy defined in the found settings.gradle file. If not, the build is executed as a single project build. Otherwise, a multi project build executed.
=Properties=
* [[Gradle_Properties#rootProject.name|rootProject.name]]

Revision as of 21:23, 17 May 2018

External

Internal

Overview

The settings.gradle file describes the build's project hierarchy. In the simplest case, there is no settings.gradle, and the build consists in just a single project, the root project. In more complex cases, various sub-project hierarchies can be specified. The file can also be used to add libraries to the build script classpath.

The configuration file is executed during the initialization phase and updates the state of the delegate [Settings] instance.


. For a single-project build, this file is optional, but required for multi-project builds: the multi-project builds must have this file in the root project.

A bootstrap settings.gradle may be created automatically on project initialization with gradle init.

The subprojects are declared in the root project settings.gradle with the "include" or "includeFlat" methods:

include 'subproject1', 'subproject2:subsubproject3'
includeFlat 'subproject1', 'subproject2'

The "include" method takes hierarchical project paths as arguments, while "includePath" expects a flat sibling structure. For more details about syntax, see Hierarchical Layout and Flat Layout.

The property access and method calls within the settings file is delegated to a Settings instance.

Resolution

  • Look at a directory called "master" on the same nesting level as the current directory.
  • If not found, search parent directories.
  • If not found, the build executes as a single project build.
  • If found, Gradle checks if the current project is part of multi-project hierarchy defined in the found settings.gradle file. If not, the build is executed as a single project build. Otherwise, a multi project build executed.

Properties