Skip to content

Commit 4e603d9

Browse files
Merge branch '2.3.x' into 2.4.x
Closes gh-24538
2 parents d6890e3 + e4d124d commit 4e603d9

File tree

5 files changed

+93
-2
lines changed

5 files changed

+93
-2
lines changed

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/docs/asciidoc/packaging-oci-image.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[[build-image]]
22
== Packaging OCI Images
3-
The plugin can create an https://github.com/opencontainers/image-spec[OCI image] using https://buildpacks.io/[Cloud Native Buildpacks] (CNB).
3+
The plugin can create an https://github.com/opencontainers/image-spec[OCI image] from an executable jar file using https://buildpacks.io/[Cloud Native Buildpacks] (CNB).
44
Images can be built using the `build-image` goal.
55

66
NOTE: For security reasons, images build and run as non-root users.
77
See the {buildpacks-reference}/reference/spec/platform-api/#users[CNB specification] for more details.
88

9+
NOTE: The `build-image` goal is not supported with projects using <<repackage, war packaging>>.
10+
911
The easiest way to get started is to invoke `mvn spring-boot:build-image` on a project.
1012
It is possible to automate the creation of an image whenever the `package` phase is invoked, as shown in the following example:
1113

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/intTest/java/org/springframework/boot/maven/BuildImageTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ void failsWhenBuilderFails(MavenBuild mavenBuild) {
164164
.containsPattern("Builder lifecycle '.*' failed with status code"));
165165
}
166166

167+
@TestTemplate
168+
void failsWithWarPackaging(MavenBuild mavenBuild) {
169+
mavenBuild.project("build-image-war-packaging").goals("package").executeAndFail(
170+
(project) -> assertThat(buildLog(project)).contains("Executable jar file required for building image"));
171+
}
172+
167173
private void writeLongNameResource(File project) {
168174
StringBuilder name = new StringBuilder();
169175
new Random().ints('a', 'z' + 1).limit(128).forEach((i) -> name.append((char) i));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>org.springframework.boot.maven.it</groupId>
6+
<artifactId>build-image-war</artifactId>
7+
<version>0.0.1.BUILD-SNAPSHOT</version>
8+
<packaging>war</packaging>
9+
<properties>
10+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
11+
<maven.compiler.source>@java.version@</maven.compiler.source>
12+
<maven.compiler.target>@java.version@</maven.compiler.target>
13+
</properties>
14+
<build>
15+
<plugins>
16+
<plugin>
17+
<groupId>@project.groupId@</groupId>
18+
<artifactId>@project.artifactId@</artifactId>
19+
<version>@project.version@</version>
20+
<executions>
21+
<execution>
22+
<goals>
23+
<goal>build-image</goal>
24+
</goals>
25+
</execution>
26+
</executions>
27+
</plugin>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-war-plugin</artifactId>
31+
<version>@maven-war-plugin.version@</version>
32+
<configuration>
33+
<archive>
34+
<manifestEntries>
35+
<Not-Used>Foo</Not-Used>
36+
</manifestEntries>
37+
</archive>
38+
</configuration>
39+
</plugin>
40+
</plugins>
41+
</build>
42+
<dependencies>
43+
<dependency>
44+
<groupId>org.springframework</groupId>
45+
<artifactId>spring-context</artifactId>
46+
<version>@spring-framework.version@</version>
47+
</dependency>
48+
<dependency>
49+
<groupId>jakarta.servlet</groupId>
50+
<artifactId>jakarta.servlet-api</artifactId>
51+
<version>@jakarta-servlet.version@</version>
52+
<scope>provided</scope>
53+
</dependency>
54+
</dependencies>
55+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2012-2020 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.test;
18+
19+
public class SampleApplication {
20+
21+
public static void main(String[] args) throws Exception {
22+
}
23+
24+
}

spring-boot-project/spring-boot-tools/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/BuildImageMojo.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,11 @@ private File getJarFile() {
230230
name.append("-").append(this.classifier);
231231
}
232232
name.append(".jar");
233-
return new File(this.sourceDirectory, name.toString());
233+
File jarFile = new File(this.sourceDirectory, name.toString());
234+
if (!jarFile.exists()) {
235+
throw new IllegalStateException("Executable jar file required for building image");
236+
}
237+
return jarFile;
234238
}
235239

236240
private BuildRequest customize(BuildRequest request) {

0 commit comments

Comments
 (0)