Skip to content

Commit fb6a9a1

Browse files
breunldetmerNils Breunese
authored
Check Maven user properties with highest precedence when fetching a property value (#4345)
* Check Maven user properties with highest precedence when fetching a property value * Fix formatting * Update changelog entry --------- Co-authored-by: ldetmer <[email protected]> Co-authored-by: Nils Breunese <[email protected]>
1 parent ec548da commit fb6a9a1

File tree

4 files changed

+208
-49
lines changed

4 files changed

+208
-49
lines changed

jib-maven-plugin/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
66
### Added
77

88
### Changed
9+
- Update retrieval of Maven properties to use the following order: user, project, system [#4344](https://github.com/GoogleContainerTools/jib/issues/4344)
910

1011
### Fixed
1112

jib-maven-plugin/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ For information about the project, see the [Jib project README](../README.md).
2727
* [Additional Build Artifacts](#additional-build-artifacts)
2828
* [Multi Module Projects](#multi-module-projects)
2929
* [Extended Usage](#extended-usage)
30-
* [System Properties](#system-properties)
30+
* [Configuration Properties](#configuration-properties)
3131
* [Global Jib Configuration](#global-jib-configuration)
3232
* [Example](#example)
3333
* [Adding Arbitrary Files to the Image](#adding-arbitrary-files-to-the-image)
@@ -344,9 +344,9 @@ Property | Type | Default | Description
344344
`executable` | string | `docker` | Sets the path to the Docker executable that is called to load the image into the Docker daemon. **Please note**: Users are responsible for ensuring that the Docker path passed in is valid and has the right permissions to be executed.
345345
`environment` | map | *None* | Sets environment variables used by the Docker executable.
346346

347-
#### System Properties
347+
#### Configuration Properties
348348

349-
Each of these parameters is configurable via commandline using system properties. Jib's system properties follow the same naming convention as the configuration parameters, with each level separated by dots (i.e. `-Djib.parameterName[.nestedParameter.[...]]=value`). Some examples are below:
349+
Each of these parameters is configurable via commandline using properties. Jib's properties follow the same naming convention as the configuration parameters, with each level separated by dots (i.e. `-Djib.parameterName[.nestedParameter.[...]]=value`). Some examples are below:
350350
```shell
351351
mvn compile jib:build \
352352
-Djib.to.image=myregistry/myimage:latest \
@@ -359,7 +359,7 @@ mvn compile jib:dockerBuild \
359359
-Djib.container.args=arg1,arg2,arg3
360360
```
361361

362-
The following table contains additional system properties that are not available as build configuration parameters:
362+
The following table contains additional properties that are not available as build configuration parameters:
363363

364364
Property | Type | Default | Description
365365
--- | --- | --- | ---

jib-maven-plugin/src/main/java/com/google/cloud/tools/jib/maven/MavenProjectProperties.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,27 @@ public static MavenProjectProperties getForProject(
132132
}
133133

134134
/**
135-
* Gets a system property with the given name. First checks for a -D commandline argument, then
136-
* checks for a property defined in the POM, then returns null if neither are defined.
135+
* Gets a property with the given name. First checks for a Maven user property (-D commandline
136+
* argument), then checks for a property defined in the POM, then checks for a Maven system
137+
* property, then returns null if none of those are defined.
137138
*
138-
* @param propertyName the name of the system property
139+
* @param propertyName the name of the property
139140
* @param project the Maven project
140141
* @param session the Maven session
141-
* @return the value of the system property, or null if not defined
142+
* @return the value of the property, or null if not defined
142143
*/
143144
@Nullable
144145
public static String getProperty(
145146
String propertyName, @Nullable MavenProject project, @Nullable MavenSession session) {
146-
if (session != null && session.getSystemProperties().containsKey(propertyName)) {
147-
return session.getSystemProperties().getProperty(propertyName);
147+
if (session != null && session.getUserProperties().containsKey(propertyName)) {
148+
return session.getUserProperties().getProperty(propertyName);
148149
}
149150
if (project != null && project.getProperties().containsKey(propertyName)) {
150151
return project.getProperties().getProperty(propertyName);
151152
}
153+
if (session != null && session.getSystemProperties().containsKey(propertyName)) {
154+
return session.getSystemProperties().getProperty(propertyName);
155+
}
152156
return null;
153157
}
154158

0 commit comments

Comments
 (0)