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 dependencies when 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 install to produce the runnable JAR.
Extract the two JARs into separate directories.
tar -zxvf demo-2.3.6.jar -C demo-2.3.6/
tar -zxvf demo-2.4.0.jar -C demo-2.4.0/Count the number of dependency JARs: version 2.3.6 contains 19, while 2.4.0 contains only 18 because the spring-boot-starter.jar is missing.
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
18What 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 dependencies from the final JAR.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>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 redis and amqp are of this type and are automatically removed during the build.
Custom JAR for Automatic Slimming
Create a MANIFEST.MF file in the JAR’s metadata and add the line Spring-Boot-Jar-Type: dependencies-starter.
resources
└── META-INF
└── MANIFEST.MFReferences
slot-maven-plugin: https://github.com/core-lib/slot-maven-plugin
start.spring.io: https://start.spring.io
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
