Settings.gradle: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
 
(6 intermediate revisions by the same user not shown)
Line 5: Line 5:
* [[Gradle_Concepts#Configuration_Scripts_and_Core_Types|Gradle Concepts]]
* [[Gradle_Concepts#Configuration_Scripts_and_Core_Types|Gradle Concepts]]
=Overview=
=Overview=
The settings file defines which projects are taking part in a multi-project build, and it is optional for a single-project build. It can also be used to add libraries to the build scripts classpath. The default name is <tt>settings.gradle</tt>. The settings file is referred to as an Gradle settings script. The file is executed during the [[Gradle_Concepts#Initialization_Phase|initialization phase]]. During execution, property access and method calls are delegated to the Settings instance.
The settings file defines which projects are taking part in a multi-project build, and it is optional for a single-project build. It can also be used to add libraries to the build scripts classpath. The default name is <tt>settings.gradle</tt>. The settings file is referred to as an Gradle settings script. The file is executed during the [[Gradle_Concepts#Initialization_Phase|initialization phase]]. During execution, property access and method calls are delegated to the [[Gradle_Settings|Settings delegate]].


=How Gradle Looks for a Settings File=
=How Gradle Looks for a Settings File=
If the [[Gradle_Command_Line#Overview|gradle command]] is executed from a directory with no settings.gradle file, Gradle looks for the file in the following way:
* It looks for settings.gradle in the parent directories. If not found, the project is executed as a single project build.
* If a settings.gradle file is found, Gradle checks if the current project is part of the multi-project hierarchy defined in that file. If it is, the multi-project build is executed, otherwise  the build is executed as a single project build.
=Example=
==Single Project Build==
<syntaxhighlight lang='groovy'>
rootProject.name = 'myProject'
</syntaxhighlight>
==Multi-Project Build==
<syntaxhighlight lang='groovy'>
rootProject.name = 'myProject'
include 'project-a'
include 'project-b'
</syntaxhighlight>
==Non-Standard Project Structure==
<syntaxhighlight lang='groovy'>
rootProject.name = 'myProject'
include 'project-a'
project(':project-a').projectDir = file('something/project-a')
</syntaxhighlight>

Latest revision as of 00:00, 15 December 2020

External

Internal

Overview

The settings file defines which projects are taking part in a multi-project build, and it is optional for a single-project build. It can also be used to add libraries to the build scripts classpath. The default name is settings.gradle. The settings file is referred to as an Gradle settings script. The file is executed during the initialization phase. During execution, property access and method calls are delegated to the Settings delegate.

How Gradle Looks for a Settings File

If the gradle command is executed from a directory with no settings.gradle file, Gradle looks for the file in the following way:

  • It looks for settings.gradle in the parent directories. If not found, the project is executed as a single project build.
  • If a settings.gradle file is found, Gradle checks if the current project is part of the multi-project hierarchy defined in that file. If it is, the multi-project build is executed, otherwise the build is executed as a single project build.

Example

Single Project Build

rootProject.name = 'myProject'

Multi-Project Build

rootProject.name = 'myProject'
include 'project-a'
include 'project-b'

Non-Standard Project Structure

rootProject.name = 'myProject'
include 'project-a'
project(':project-a').projectDir = file('something/project-a')