I read in https://github.com/spring-projects/spring-boot/commit/08e96427deb59c24a7d93f673284db3287538e25 [Add command-line properties for Maven build-image options] that "per Maven conventions, a value in pom.xml configuration will override a command-line property when both are provided." I am kind of doubting if that's really the convention. I saw for example on the page for Maven 1 (couldn't find it for Maven 3): http://maven.apache.org/archives/maven-1.x/reference/properties.html
The last definition takes precedence, so ${user.home}/build.properties will override anything specified in a project, and properties given on the command line using -D will override everything.
And on this popular StackOverflow response: https://stackoverflow.com/questions/17332857/how-to-use-the-mvn-d-to-set-multiple-properties-in-maven-via-command-line
If propertyName already exists in the pom.xml, its value will be overwritten by the one passed as argument via -D.
My use case is to provide a default Docker image name in the POM (a simple and local ${project.artifactId}
), whereas I'd like to override this value on the command line with -D
.
Due to the check if image.name == null
on https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java#L182, a command line value will indeed not override if already defined in the POM.
Would you consider changing this behavior?
Comment From: scottfrederick
The links you provided refer to the order of precedence of Maven project properties. The commit you referenced discusses the order of precedence for Maven MOJO configuration parameters, which is something different. Project property precedence is clearly documented (updated link is here: https://maven.apache.org/pom.html#Properties). MOJO parameter precedence is not clearly documented, but by observation we know that a MOJO parameter value provided in the pom.xml file will override a parameter value provided on the command line, and we won't implement our MOJOs in a way that conflicts with this behavior.
My use case is to provide a default Docker image name in the POM (a simple and local ${project.artifactId}), whereas I'd like to override this value on the command line with -D.
You can achieve this goal using a combination of a user-provided project property and MOJO configuration. For example, define a project property and use that property in the plugin configuration:
<properties>
<imageName>${project.artifactId}:${project.version}</imageName>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<name>${imageName}</name>
</image>
</configuration>
</plugin>
</plugins>
</build>
You can then override the project property on the command line:
$ mvn spring-boot:build-image -DimageName=custom-image-name