Add command-line properties for Maven build-image options

This commit adds support for setting the image name and builder
parameters of the Maven spring-boot:build-image goal using command-line
properties as an alternative to plugin configuration in pom.xml. Per
Maven conventions, a value in pom.xml configuration will override a
command-line property when both are provided.

Fixes gh-20520
This commit is contained in:
Scott Frederick
2020-03-17 18:40:37 -05:00
parent f470f27666
commit 08e96427de
5 changed files with 94 additions and 21 deletions

View File

@@ -81,8 +81,8 @@ public abstract class AbstractPackagerMojo extends AbstractDependencyFilterMojo
/**
* The type of archive (which corresponds to how the dependencies are laid out inside
* it). Possible values are JAR, LAYERED_JAR, WAR, ZIP, DIR, NONE. Defaults to a guess
* based on the archive type.
* it). Possible values are JAR, WAR, ZIP, DIR, NONE. Defaults to a guess based on the
* archive type.
* @since 1.0.0
*/
@Parameter(property = "spring-boot.repackage.layout")

View File

@@ -101,6 +101,20 @@ public class BuildImageMojo extends AbstractPackagerMojo {
@Parameter
private Image image;
/**
* Alias for {@link Image#name to support configuration via command-line property.
* @since 2.3.0
*/
@Parameter(property = "spring-boot.build-image.imageName", readonly = true)
String imageName;
/**
* Alias for {@link Image#builder to support configuration via command-line property.
* @since 2.3.0
*/
@Parameter(property = "spring-boot.build-image.builder", readonly = true)
String imageBuilder;
@Override
public void execute() throws MojoExecutionException {
if (this.project.getPackaging().equals("pom")) {
@@ -129,6 +143,12 @@ public class BuildImageMojo extends AbstractPackagerMojo {
private BuildRequest getBuildRequest(Libraries libraries) {
Function<Owner, TarArchive> content = (owner) -> getApplicationContent(owner, libraries);
Image image = (this.image != null) ? this.image : new Image();
if (image.name == null && this.imageName != null) {
image.setName(this.imageName);
}
if (image.builder == null && this.imageBuilder != null) {
image.setBuilder(this.imageBuilder);
}
return customize(image.getBuildRequest(this.project.getArtifact(), content));
}

View File

@@ -32,6 +32,7 @@ import org.springframework.util.StringUtils;
* Image configuration options.
*
* @author Phillip Webb
* @author Scott Frederick
* @since 2.3.0
*/
public class Image {
@@ -61,6 +62,14 @@ public class Image {
*/
boolean verboseLogging;
void setName(String name) {
this.name = name;
}
void setBuilder(String builder) {
this.builder = builder;
}
BuildRequest getBuildRequest(Artifact artifact, Function<Owner, TarArchive> applicationContent) {
return customize(BuildRequest.of(getOrDeduceName(artifact), applicationContent));
}