The Paketo Buildpack for Spring Boot is a Cloud Native Buildpack that contributes Spring Boot dependency information and slices an application into multiple layers.
This buildpack will always detect.
This buildpack will participate at build time if all the following conditions are met:
<APPLICATION_ROOT>/META-INF/MANIFEST.MFcontains aSpring-Boot-Versionentry
The buildpack will do the following:
- Contributes Spring Boot version to
org.springframework.boot.versionimage label - If
<APPLICATION_ROOT>/META-INF/dataflow-configuration-metadata.propertiesexists- Contributes Spring Boot configuration metadata to
org.springframework.boot.spring-configuration-metadata.jsonimage label - Contributes Spring Cloud Data Flow configuration metadata to
org.springframework.cloud.dataflow.spring-configuration-metadata.jsonimage label
- Contributes Spring Boot configuration metadata to
- Contributes
Implementation-Titlemanifest entry toorg.opencontainers.image.titleimage label - Contributes
Implementation-versionmanifest entry toorg.opencontainers.image.versionimage label - Contributes dependency information extracted from Maven naming conventions to the image's BOM
- When contributing to a JVM application:
- Contributes Spring Cloud Bindings as an application dependency
- This enables bindings-aware Spring Boot auto-configuration when CNB bindings are present during launch
- The version of the Spring Cloud Bindings library to install will be determined by (in order):
- An explicit value set in
BP_SPRING_CLOUD_BINDINGS_VERSIONby the user - The Spring Boot version from
<APPLICATION_ROOT>/META-INF/MANIFEST.MF: Boot 2.x will install Spring Cloud Bindings v1, Boot 3.x to 4.1 will install Spring Cloud Bindings v2
- An explicit value set in
- With Spring Boot 4.2 and later, Spring Cloud Bindings is not contributed unless
BP_SPRING_CLOUD_BINDINGS_VERSIONis set, as no released version supports it
- If
<APPLICATION_ROOT>/META-INF/MANIFEST.MFcontains aSpring-Boot-Layers-Indexentry- Contributes application slices as defined by the layer's index
- If the application is a reactive web application
- Configures
$BPL_JVM_THREAD_COUNTto 50
- Configures
- If the application is AOT instrumented (presence of
META-INF/native-imagefolder) ANDBP_SPRING_AOT_ENABLEDis set totrue- set
BPL_SPRING_AOT_ENABLEDto true - add
-Dspring.aot.enabled=truetoJAVA_TOOL_OPTIONSat runtime
- set
- If the application is AOT instrumented (presence of
META-INF/native-imagefolder) ANDBP_SPRING_AOT_ENABLEDis set totrueANDTRAINING_RUN_JAVA_TOOL_OPTIONS(or deprecated CDS_TRAINING_JAVA_TOOL_OPTIONS`) is set- fail the build with "build failed because of invalid user configuration" - the reason being is that the AOT classes used during training run won't be compatible with a different set of
JAVA_TOOL_OPTIONSat runtime - the Spring team explains this issue in detail here: spring-projects/spring-boot#41348
- fail the build with "build failed because of invalid user configuration" - the reason being is that the AOT classes used during training run won't be compatible with a different set of
- Contributes Spring Cloud Bindings as an application dependency
- If
<APPLICATION_ROOT>/META-INF/MANIFEST.MFcontains aSpring-Boot-Native-Processedentry OR if$BP_MAVEN_ACTIVE_PROFILEScontains thenativeprofile:- A build plan entry is provided,
native-image-application, which can be required by thenative-imagebuildpack to automatically trigger a native image build
- A build plan entry is provided,
- When contributing to a native image application:
- Adds classes from the executable JAR and entries from
classpath.idxto the build-time class path, so they are available tonative-image
- Adds classes from the executable JAR and entries from
| Environment Variable | Description |
|---|---|
$BP_SPRING_CLOUD_BINDINGS_DISABLED |
Whether to contribute Spring Cloud Bindings support to the image at build time. Defaults to false. |
$BPL_SPRING_CLOUD_BINDINGS_DISABLED |
Whether to auto-configure Spring Boot environment properties from bindings at runtime. This requires Spring Cloud Bindings to have been installed at build time or it will do nothing. Defaults to false. |
$BPL_SPRING_CLOUD_BINDINGS_ENABLED |
Deprecated in favour of $BPL_SPRING_CLOUD_BINDINGS_DISABLED. Whether to auto-configure Spring Boot environment properties from bindings at runtime. This requires Spring Cloud Bindings to have been installed at build time or it will do nothing. Defaults to true. |
$BP_SPRING_CLOUD_BINDINGS_VERSION |
Explicit version of Spring Cloud Bindings library to install. |
$BP_SPRING_AOT_ENABLED |
Whether to contribute $BPL_SPRING_AOT_ENABLED at runtime. Beware that the Spring Boot app needs to have been AOT instrumented (presence of META-INF/native-image) too. Defaults to false. |
$BPL_SPRING_AOT_ENABLED |
Whether to contribute -Dspring.aot.enabled=true to JAVA_TOOL_OPTIONS at runtime. Defaults to yes if the above conditions were met; false otherwise |
$BP_UNPACK_LAYOUT_ONLY |
Whether to only unpack the Spring Boot app, and not apply a CDS / AOT Cache training run |
$BP_JVM_CDS_ENABLED |
Deprecated, use BP_JVM_AOTCACHE_ENABLED - Whether to perform the CDS training run (that will generate the caching file application.jsa). Defaults to false. |
$BPL_JVM_CDS_ENABLED |
Deprecated, use BPL_JVM_AOTCACHE_ENABLED - Whether to load the CDS caching file (-XX:SharedArchiveFile=application.jsa) that was generated during the CDS training run. Defaults to the value of BP_JVM_CDS_ENABLED |
$BP_JVM_AOTCACHE_ENABLED |
Whether to perform the AOT Cache training run (that will generate the caching file application.jsa). Defaults to false. |
$BP_JVM_AOTCACHE_PATH |
Path of a pre-recorded AOT cache. Relative values are resolved against the application directory, absolute values are used as-is. Defaults to aot-cache/application.aot; if set to a non-blank value and no cache is found there, the build fails rather than falling back to a training run. |
$BPL_JVM_AOTCACHE_ENABLED |
Whether to load the CDS caching file (-XX:SharedArchiveFile=application.jsa) that was generated during the CDS training run. Defaults to the value of BP_JVM_CDS_ENABLED |
$BPL_JVM_AOTCACHE |
Path of a pre-recorded AOT cache to load (-XX:AOTCache=<path>). Set by the buildpack when the application ships a pre-recorded cache (see BP_JVM_AOTCACHE_PATH). Takes precedence over BPL_JVM_AOTCACHE_ENABLED |
$CDS_TRAINING_JAVA_TOOL_OPTIONS |
Deprecated, use TRAINING_RUN_JAVA_TOOL_OPTIONS - Allow the user to override the default JAVA_TOOL_OPTIONS, only for the CDS training run. Useful to configure your app not to reach external services during training run for example. |
$TRAINING_RUN_JAVA_TOOL_OPTIONS |
Allow the user to override the default JAVA_TOOL_OPTIONS, only for training run. Useful to configure your app not to reach external services during training run for example. |
Instead of letting the buildpack record the AOT cache with a training run, an application can ship
one it recorded itself, at aot-cache/application.aot (or wherever BP_JVM_AOTCACHE_PATH points;
a relative value is taken from the application directory, an absolute value is used as-is). The
buildpack then skips the training run, puts the cache in a launch layer and points
BPL_JVM_AOTCACHE at it.
An AOT cache only loads on the JDK version and the architecture that recorded it, and only with
the classpath and timestamps it was recorded against, which here means runner.jar plus lib/
in the extracted application directory. The buildpack asks the image JRE to load the cache with
-XX:AOTMode=on before accepting it, so a cache that does not belong to the image fails the build
instead of silently costing the optimization at runtime. No separate metadata file is needed: the
JVM itself is the authority on which caches it will load.
Building from source, BP_INCLUDE_FILES carries the cache through the Maven or Gradle build:
pack build my-app \
--env BP_JVM_AOTCACHE_ENABLED=true \
--env BP_JVM_VERSION=25 \
--env BP_INCLUDE_FILES='aot-cache/application.aot'Building from an already packaged archive, the cache has to be inside it, under aot-cache/:
pack build my-app --path target/my-app-0.0.1.jar \
--env BP_JVM_AOTCACHE_ENABLED=true \
--env BP_JVM_VERSION=25An empty cache, or an image whose JRE is older than Java 24, is ignored and the training run
happens as usual. Loading a cache needs Java 24 (-XX:AOTCache); it is recording one in a single
step that needs Java 25 (-XX:AOTCacheOutput), which is why the training run only produces
application.aot from Java 25 on.
Some applications exit with a non-zero status from their own shutdown path — a shutdown hook, a
library's atexit handler, a non-daemon thread — after the JVM has already finished writing the
cache. That status belongs to the application rather than to the cache, so the training run is
judged on what it produced: if the cache exists, is not empty, and the image JRE loads it
(-XX:AOTMode=on), the build keeps it and logs the failure instead of stopping. A run that
produced no usable cache still fails the build.
The buildpack optionally accepts the following bindings:
| Key | Value | Description |
|---|---|---|
<dependency-digest> |
<uri> |
If needed, the buildpack will fetch the dependency with digest <dependency-digest> from <uri> |
This buildpack is released under version 2.0 of the Apache License.