Using cloud-native buildpacks with Spring Boot < 2.3

479 Views Asked by At

Spring Boot 2.3 introduced support for building optimized Docker images using the Spring Boot maven/gradle plugin. The spring-boot:build-image goal does a bunch of things:

  • Create the layers index
  • Invoke the Paketo buildpack
  • Build the OCI image
  • etc.

Is there a way to replicate these steps for modules using an older Spring Boot version? Even better, can these steps be integrated directly into a maven/gradle build?

1

There are 1 best solutions below

0
On

As the layered jars feature (incl. layers.idx file generation and spring-boot-maven-plugin support for Cloud Native Buildpacks / Paketo.io) was introduced in Spring Boot 2.3 I would say that you can't really downgrade it with the standard tooling.

BUT I guess you could try to generate the layers.idx file yourself - or even choose a default file, since the layout of your app may not change that much after all. A example would be (using no SNAPSHOT depencencies):

- "dependencies":
  - "BOOT-INF/lib/"
- "spring-boot-loader":
  - "org/"
- "snapshot-dependencies":
- "application":
  - "BOOT-INF/classes/"
  - "BOOT-INF/classpath.idx"
  - "BOOT-INF/layers.idx"
  - "META-INF/"

Having this file in place (means place it into your target folder (maybe you could automate that with a simple Maven plugin for example)), pack CLI should be able to pick it up. So install pack CLI and run a Paketo build without using the spring-boot-maven-plugin yourself like this:

pack build yourAppNameHere --path . --builder paketobuildpacks/builder:base

I didn't really tried this approach myself - and maybe you run into problems, if the directory structure is much different in older Spring Boot versions. But I would appreciate to hear some feedback!