spring-bootbuildpackpaketo

How to Override paketo-buildpacks/bellsoft-liberica for `mvn spring-boot:build-image`


I want to create OCI images with different JVM bases using Spring Boot's build-image goal. However, I am having difficulty finding documentation for overriding the JVM. Can anyone let me know how to override just the JVM varients say " paketo-buildpacks/adoptium"?

My pom file looks like the one below.

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <image>
                    <builder>jfrog.mycompany.com/paketobuildpacks/builder:base</builder>
                    <runImage>jfrog.mycompany.com/paketobuildpacks/run:base-cnb</runImage>
                </image>
                <excludes>
                    <exclude>
                        <groupId>org.projectlombok</groupId>
                        <artifactId>lombok</artifactId>
                    </exclude>
                </excludes>
            </configuration>
        </plugin>

I tried checking the Spring boot plugin as well as paketo documentaion. But there is no stratight forward examples or instructions.


Solution

  • The instructions for using different JVM vendors can be found here.

    https://paketo.io/docs/howto/java/#use-an-alternative-jvm

    The official instructions use pack not Spring Boot build tools, but the process is the same. You need to override the buildpack order and set your preferred JVM vendor's buildpack to run first. The first JVM vendor buildpack that runs will install a JRE/JDK and any others will just no-op.

    Here are the docs for using Maven Spring Boot Build tools to set a custom buildpack order.

    https://docs.spring.io/spring-boot/docs/3.0.6/maven-plugin/reference/htmlsingle/#build-image.examples.buildpacks

    Example:

    <project>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <configuration>
                        <image>
                            <buildpacks>
                                <buildpack>gcr.io/paketo-buildpacks/adoptium</buildpack>
                                <buildpack>urn:cnb:builder:paketo-buildpacks/java</buildpack>
                            </buildpacks>
                        </image>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>
    

    That should do it. When your build runs, you should see your custom JVM vendor's buildpack run first and install the JRE/JDK.