Spring Boot’s Maven and Gradle plugins give you a streamlined path from source code to a runnable artifact. Whether you need a self-contained fat JAR, layered images for Docker, or a dependency-only library JAR, this guide walks you through the most common build tasks step by step.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
Create an executable fat JAR
Thespring-boot-maven-plugin and the Gradle bootJar task both produce a self-contained executable JAR that embeds your application classes together with all runtime dependencies.
- Maven
- Gradle
If you inherit from Without the parent POM you must add an explicit
spring-boot-starter-parent, declare the plugin without a version and run ./mvnw package:pom.xml
<executions> block that binds the repackage goal:pom.xml
The executable JAR packages your application classes under
BOOT-INF/classes and runtime dependencies under BOOT-INF/lib. This structure means the archive cannot be used directly as a library dependency by other projects.Add build information to the Actuator /info endpoint
Both plugins can generate a build-info.properties file at build time. When the file is present, Spring Boot auto-configures a BuildProperties bean and the Actuator /actuator/info endpoint exposes the coordinates automatically.
- Maven
- Gradle
Add an execution for the
build-info goal:pom.xml
application.properties
Generate Git commit information
Both Maven and Gradle can write agit.properties file that surfaces repository metadata in the /actuator/info endpoint.
- Maven
- Gradle
Add the Git Commit Id plugin (pre-configured in
spring-boot-starter-parent):pom.xml
Manage dependency versions with the Spring Boot BOM
Spring Boot ships a curated Bill of Materials (spring-boot-dependencies) that pins the versions of hundreds of common libraries. You do not need to specify individual versions for managed dependencies.
- Maven
- Gradle
Inherit from To override a single managed version, set the corresponding property:
spring-boot-starter-parent to get full BOM management:pom.xml
pom.xml
Customize the main class
By default the plugins detect the class withpublic static void main(String[] args) automatically. If your project has multiple candidates, specify the main class explicitly.
- Maven
- Gradle
pom.xml
Use a Spring Boot application as a library dependency
Because executable JAR classes live underBOOT-INF/classes, other projects cannot find them on the classpath. The recommended solution is to extract shared code into a separate Maven/Gradle module. When that is not possible, configure the plugin to produce two artifacts: a standard JAR for use as a dependency and a classified executable JAR.
- Maven
Apply an
exec classifier to the executable archive so the default artifact remains a plain JAR:pom.xml
Exclude files from the non-executable library JAR
When you publish both an executable and a non-executable JAR, you may want to exclude application-specific files (such asapplication.yaml) from the library artifact.
pom.xml
Configure layered JARs for efficient Docker images
Layered JARs split the executable archive into distinct layers (dependencies, Spring Boot loader, snapshot dependencies, application classes) so that Docker can cache unchanged layers between builds. This significantly reduces image push and pull times.- Maven
- Gradle
Layered JAR mode is enabled by default when you use the Spring Boot Maven plugin. To build the image with Cloud Native Buildpacks:To introspect the layers in the produced JAR:
Generate a CycloneDX SBOM
Maven
Maven
The
spring-boot-starter-parent POM pre-configures the CycloneDX Maven plugin. Declare it to activate SBOM generation at build time:pom.xml
Gradle
Gradle
Apply the CycloneDX Gradle plugin:
build.gradle
Multi-module project layout
In a multi-module build, place the Spring Boot plugin only on the module that produces the runnable application. Sibling library modules should use the standardjar packaging without the repackage goal, so they remain usable as dependencies.
Extract specific libraries when an executable JAR runs
Some libraries (for example, JRuby) expect to be available as a real file on disk rather than inside a JAR. Mark them for unpacking so the launcher extracts them to the system temporary directory before the JVM loads them.pom.xml