Gradle Project Coordinates, State and Configured Properties: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 28: Line 28:
project(':').name = "blue"
project(':').name = "blue"
</syntaxhighlight>
</syntaxhighlight>
Multi-project build:
For a multi-project build, the name of the root project can be set as above, and the name of a sub-project can be set specifying its path:
<syntaxhighlight lang='groovy'>
<syntaxhighlight lang='groovy'>
// root project name, the following assignments are equivalent:
rootProject.name = "blue"
project(':').name = "blue"
// sub-project
project(':subproject-01').name = "green"
project(':subproject-01').name = "green"
</syntaxhighlight>
</syntaxhighlight>

Revision as of 02:25, 4 October 2020

Internal

Overview

Project-identifying information such as name, group, version, description and path are referred to as "project coordinates". The terminology comes from Maven, where a project name, group and version uniquely identify a project artifact. Gradle project coordinates map onto Maven project coordinates, as described in the Compatibility with Maven Project Coordinates section.

Different project coordinates can be set in different locations. The project name can only be set in settings.gradle, while the group, version, description can only be set and read in build.gradle. More details are provided in their corresponding section.

The coordinates are available as values of DSL variables and programmatically via the Project API.

Compatibility with Maven Project Coordinates

Gradle produces by default artifacts that are compatible with Maven repositories, so Gradle translates its project coordinates into Maven project coordinates. The translation rules are described in the name, group and version sections: the project name becomes artifactId,

Coordinates

Name

The project name is a string that identifies the project. The project name is initialized by default with the name of the directory that contains the project's build.gradle. The name is not necessarily unique within a project hierarchy, the unique identifier for the project in a hierarchy is its path.

If the project name must be set to a value different from its directory, it can be set in settings.gradle, for both a simple project and multi-project.

For a simple project, rootProject and project(':') are the same, so the following assignments are equivalent::

rootProject.name = "blue"
project(':').name = "blue"

For a multi-project build, the name of the root project can be set as above, and the name of a sub-project can be set specifying its path:

project(':subproject-01').name = "green"

The project name can be read as value of the DSL element "name":

println "${name}"
println project.name

The project name can be also obtained programmatically during the build with Project.getName().

Maven artifactId

The project name automatically becomes the Maven project name coordinate, artifactId.

More details about artifactId:

Maven artifactId

Group

Maven groupId

The group information must be specified when generating a Maven artifact. If the group information is missing, Maven Publish plugin will complain that "groupId cannot be empty".

Version

Maven version

If the project does not configure a version, the corresponding Maven version will be empty - the artifact will not cary any version information.

Description

Path

Project Directory

TODO

  • Verify that name, group and version can be set in settings.gradle. How? Via the ProjectDescriptor interface.