Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check Maven user properties with highest precedence when fetching a property value #4345

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ All notable changes to this project will be documented in this file.
## [unreleased]

### Added
- Check Maven user properties with highest precedence when fetching a property value ([#4344](https://github.com/GoogleContainerTools/jib/issues/4344))

### Changed

Expand Down
8 changes: 4 additions & 4 deletions jib-maven-plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ For information about the project, see the [Jib project README](../README.md).
* [Additional Build Artifacts](#additional-build-artifacts)
* [Multi Module Projects](#multi-module-projects)
* [Extended Usage](#extended-usage)
* [System Properties](#system-properties)
* [Configuration Properties](#configuration-properties)
* [Global Jib Configuration](#global-jib-configuration)
* [Example](#example)
* [Adding Arbitrary Files to the Image](#adding-arbitrary-files-to-the-image)
Expand Down Expand Up @@ -344,9 +344,9 @@ Property | Type | Default | Description
`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.
`environment` | map | *None* | Sets environment variables used by the Docker executable.

#### System Properties
#### Configuration Properties

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:
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:
```shell
mvn compile jib:build \
-Djib.to.image=myregistry/myimage:latest \
Expand All @@ -359,7 +359,7 @@ mvn compile jib:dockerBuild \
-Djib.container.args=arg1,arg2,arg3
```

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

Property | Type | Default | Description
--- | --- | --- | ---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@ public static MavenProjectProperties getForProject(
}

/**
* Gets a system property with the given name. First checks for a -D commandline argument, then
* checks for a property defined in the POM, then returns null if neither are defined.
* Gets a property with the given name. First checks for a Maven user property (-D commandline
* argument), then checks for a property defined in the POM, then checks for a Maven system
* property, then returns null if none of those are defined.
*
* @param propertyName the name of the system property
* @param propertyName the name of the property
* @param project the Maven project
* @param session the Maven session
* @return the value of the system property, or null if not defined
* @return the value of the property, or null if not defined
*/
@Nullable
public static String getProperty(
String propertyName, @Nullable MavenProject project, @Nullable MavenSession session) {
if (session != null && session.getSystemProperties().containsKey(propertyName)) {
return session.getSystemProperties().getProperty(propertyName);
if (session != null && session.getUserProperties().containsKey(propertyName)) {
return session.getUserProperties().getProperty(propertyName);
}
if (project != null && project.getProperties().containsKey(propertyName)) {
return project.getProperties().getProperty(propertyName);
}
if (session != null && session.getSystemProperties().containsKey(propertyName)) {
return session.getSystemProperties().getProperty(propertyName);
}
return null;
}

Expand Down
Loading