The spring-boot-maven-plugin can create an OCI image from a jar or war file using Cloud Native Buildpacks.
By default it uses a buildpack called paketo-buildpacks/bellsoft-liberica
which is based on Bellsoft Liberica JDK.
The list of all Java buildpacks is available in Paketo Buildpacks Reference.
To choose another JVM in spring-boot-maven-plugin, first you need to find the buildpacks that are used by default. Run mvn spring-boot:build-image
and look for something like this:
[INFO] [creator] ===> DETECTING
[INFO] [creator] 6 of 26 buildpacks participating
[INFO] [creator] paketo-buildpacks/ca-certificates 3.6.1
[INFO] [creator] paketo-buildpacks/bellsoft-liberica 10.1.0
[INFO] [creator] paketo-buildpacks/syft 1.27.0
[INFO] [creator] paketo-buildpacks/executable-jar 6.6.3
[INFO] [creator] paketo-buildpacks/dist-zip 5.5.2
[INFO] [creator] paketo-buildpacks/spring-boot 5.23.0
That´s the list of buildpacks being used. We need to change Bellsoft Liberica to the desired JVM.
So, to use Microsoft OpenJDK, copy the buildpacks from above, but change paketo-buildpacks/bellsoft-liberica
to gcr.io/paketo-buildpacks/microsoft-openjdk
. The pom.xml
should be:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildpacks>
<buildpack>paketo-buildpacks/ca-certificates</buildpack>
<buildpack>gcr.io/paketo-buildpacks/microsoft-openjdk</buildpack>
<buildpack>paketo-buildpacks/syft</buildpack>
<buildpack>paketo-buildpacks/executable-jar</buildpack>
<buildpack>paketo-buildpacks/dist-zip</buildpack>
<buildpack>paketo-buildpacks/spring-boot</buildpack>
</buildpacks>
</image>
</configuration>
</plugin>
Now, run mvn spring-boot:build-image
and verify that Microsoft OpenJDK is being used:
[INFO] [creator] Paketo Buildpack for Microsoft OpenJDK 3.0.1
[INFO] [creator] https://github.com/paketo-buildpacks/microsoft-openjdk
...
[INFO] [creator] Microsoft OpenJDK 17.0.6: Contributing to layer
[INFO] [creator] Downloading from https://aka.ms/download-jdk/microsoft-jdk-17.0.6-linux-x64.tar.gz
Top comments (0)