diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java index a72373c06b7..a681b031906 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/Image.java @@ -257,7 +257,7 @@ public class Image { if (StringUtils.hasText(this.runImage)) { request = request.withRunImage(ImageReference.of(this.runImage)); } - if (this.env != null && !this.env.isEmpty()) { + if (!CollectionUtils.isEmpty(this.env)) { request = request.withEnv(this.env); } if (this.cleanCache != null) { @@ -298,7 +298,7 @@ public class Image { if (this.securityOptions != null) { request = request.withSecurityOptions(this.securityOptions); } - if (this.imagePlatform != null) { + if (StringUtils.hasText(this.imagePlatform)) { request = request.withImagePlatform(this.imagePlatform); } return request; diff --git a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java index 053ec87bd8e..12b37605436 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/ImageTests.java @@ -49,6 +49,7 @@ import static org.assertj.core.api.Assertions.entry; * @author Scott Frederick * @author Jeroen Meijer * @author Rafael Ceccone + * @author Moritz Halbritter */ class ImageTests { @@ -290,6 +291,14 @@ class ImageTests { assertThat(request.getImagePlatform()).isEqualTo(ImagePlatform.of("linux/arm64")); } + @Test + void getBuildRequestWhenImagePlatformIsEmptyDoesntSetImagePlatform() { + Image image = new Image(); + image.imagePlatform = ""; + BuildRequest request = image.getBuildRequest(createArtifact(), mockApplicationContent()); + assertThat(request.getImagePlatform()).isNull(); + } + private Artifact createArtifact() { return new DefaultArtifact("com.example", "my-app", VersionRange.createFromVersion("0.0.1-SNAPSHOT"), "compile", "jar", null, new DefaultArtifactHandler());