How Spring Boot 2.4 Automatically Trims Empty Starter JARs
Spring Boot 2.4 introduces automatic removal of empty starter dependencies when building executable JARs, reducing size by eliminating unnecessary starter JARs; this guide demonstrates the effect, explains what empty starters are, and shows how to customize JARs for automatic slimming using manifest entries.
Automatic Jar Slimming
Spring Boot projects have long suffered from large executable JAR sizes because all dependency JARs are bundled. While plugins like slot-maven-plugin can separate dependencies from the runnable JAR, they do not reduce the size of the original dependency JARs.
Spring Boot 2.4 adds a feature that automatically removes
empty starter dependencieswhen building the runnable JAR, effectively slimming the output.
Demo Results
First, build runnable JARs with Spring Boot 2.4.0 and Spring Boot 2.3.6, then discuss what an empty starter is.
Use start.spring.io to create an empty Spring Boot project, ensuring no dependencies are added.
Run
mvn clean installto produce the runnable JAR.
Extract the two JARs into separate directories.
<code>tar -zxvf demo-2.3.6.jar -C demo-2.3.6/
tar -zxvf demo-2.4.0.jar -C demo-2.4.0/</code>Count the number of dependency JARs: version 2.3.6 contains 19, while 2.4.0 contains only 18 because the
spring-boot-starter.jaris missing.
<code>cd demo-2.3.6/BOOT-INF/lib && ll -h | wc -l
19
cd demo-2.4.0/BOOT-INF/lib && ll -h | wc -l
18</code>What Is an Empty Starter?
When creating a project via start.spring.io, a starter is added by default, but Spring Boot 2.4 automatically deletes these
empty starter dependenciesfrom the final JAR.
<code><dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency></code>The special characteristics of a spring-boot-starter are:
It is an empty JAR that contains no code.
It references other JARs solely to import them in bulk.
Because such JARs have no functional code, they are unnecessary in the executable JAR; most starters like
redisand
amqpare of this type and are automatically removed during the build.
Custom JAR for Automatic Slimming
Create a
MANIFEST.MFfile in the JAR’s metadata and add the line
Spring-Boot-Jar-Type: dependencies-starter.
<code>resources
└── META-INF
└── MANIFEST.MF</code>References
slot-maven-plugin: https://github.com/core-lib/slot-maven-plugin
start.spring.io: https://start.spring.io
Java Architecture Diary
Committed to sharing original, high‑quality technical articles; no fluff or promotional content.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.