Backend Development 5 min read

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.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
How Spring Boot 2.4 Automatically Trims Empty Starter JARs

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.

<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.jar

is 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 dependencies

from 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

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

.

<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

Backend DevelopmentSpring BootJar SlimmingEmpty Starter
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.