Sub topic 1
Dependency management: the Boot parent and BOM
Every Spring Boot project starts with a question that has nothing to do with Spring beans: which versions of which libraries go together? Boot answers it with a curated set of versions that the Boot team tests as a unit. This chapter explains where that set lives, how your build picks it up, and how to override it safely. Later chapters build on it, because a starter works without a version number only because of this mechanism.
Prerequisites
This chapter assumes you can do the following:
- Read a Maven
pom.xmlor a Gradle build file and tell dependencies from plugins. - Run a Spring Boot application from the command line or an IDE.
- Explain what a transitive dependency is, meaning a library pulled in by one of your direct dependencies.
You don't need to know how auto-configuration works yet. That starts in later chapters.
The problem Boot solves
A typical web application uses Spring MVC, Jackson, Tomcat, a logging stack, and a validation library. Each of these has its own release cycle. If you pick versions by hand, you can end up with a Jackson module that expects a newer Jackson core, or a Tomcat release that Spring Framework has not been tested against. These conflicts often show up at runtime as NoSuchMethodError or ClassNotFoundException, not at build time.
Boot's solution is a Bill of Materials (BOM). A BOM is a POM file that lists recommended versions for many libraries and contains no code. It says "if you use library X, use version Y", and it does not add anything to your classpath by itself.
Where the versions live: spring-boot-dependencies
The BOM is the artifact org.springframework.boot:spring-boot-dependencies. Its dependencyManagement section lists versions for Spring's own projects and for a large set of third-party libraries, including Jackson, Hibernate, Tomcat, Logback, JUnit, and Mockito. It defines each version as a property, for example jackson-bom.version, so you can override a single library without touching the rest.
Maven's dependencyManagement section is a table of default versions. A dependency listed there still has to appear in your <dependencies> section (directly or transitively) to reach the classpath. Once it does, Maven fills in the version from the table when you omit it.
You can get this table into your build in two ways: inherit it through spring-boot-starter-parent, or import it.
Option 1: the starter parent
The most common setup makes spring-boot-starter-parent the parent of your project:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/>
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>Use the current Boot release in place of 3.4.0. The <relativePath/> element tells Maven to resolve the parent from the repository and not to look in the parent directory.
Notice that the spring-boot-starter-web dependency has no <version>. The parent supplies it. The same goes for the spring-boot-maven-plugin.
The parent does more than manage dependency versions. spring-boot-starter-parent itself inherits from spring-boot-dependencies, and it adds build defaults:
- The
java.versionproperty sets the compiler release level. - Source files and resources are read as UTF-8.
- The
spring-boot-maven-pluginis configured with arepackagegoal, which turns your build output into an executable "fat" JAR. - The compiler plugin passes
-parameters, so reflection can see method parameter names. - Resource filtering uses
@...@placeholders inapplication*.propertiesandapplication*.yml, which avoids clashes with Spring's own${...}syntax.
Option 2: import the BOM
Many organizations already have a corporate parent POM, and Maven allows only one parent. In that case, import the BOM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>You get the version table, and nothing else. The parent's build defaults are gone, so you have to configure these yourself: the Java release level, the encoding, and the repackage execution of the Boot plugin. Property overrides also work differently, as shown below.
| Aspect | `spring-boot-starter-parent` | Imported `spring-boot-dependencies` |
|---|---|---|
| Uses your single Maven parent slot | Yes | No |
| Manages dependency versions | Yes | Yes |
| Sets encoding, Java level, plugin defaults | Yes | No, configure them yourself |
| Override a version with a property | Yes | No, declare the dependency first |
Gradle
Gradle has no parent POM, so the equivalent is a plugin that applies the same version table:
plugins {
id 'java'
id 'org.springframework.boot' version '3.4.0'
id 'io.spring.dependency-management' version '1.1.6'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
}The io.spring.dependency-management plugin reads the Boot BOM and supplies the versions. Gradle can also consume the BOM natively with implementation platform(org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES), which does not need the dependency-management plugin.
Overriding a managed version
Sometimes you need a different version than Boot manages, for example to pick up a security fix before the next Boot release. You have three options, listed from safest to riskiest.
Override the version property
With the starter parent, set the property that the BOM uses:
<properties>
<jackson-bom.version>2.18.2</jackson-bom.version>
</properties>This is the best option. The BOM applies the new version consistently to every artifact that uses the property, so related artifacts stay aligned. Look up the property name in the spring-boot-dependencies POM, because it does not always match the artifact name.
With the Gradle dependency-management plugin, the same override is ext['jackson-bom.version'] = '2.18.2'.
Override with an explicit version
You can put a <version> directly on a dependency:
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.2</version>
</dependency>This changes only that one artifact. Sibling artifacts such as jackson-core stay on the managed version, and this is the usual way to end up with a mismatched set.
Override when you import the BOM
An imported BOM ignores your project properties. To override, declare the version in your own dependencyManagement section before the import. Maven uses the first declaration it finds:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>2.18.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.4.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>What the BOM does not cover
The BOM manages versions only for libraries Boot chooses to include. If you add a library that is not in the table, you must give it a version yourself. Managed versions also apply to your direct dependencies and to transitive ones. A transitive dependency pulled in by a third-party library is forced to the managed version if it appears in the table, even when that library asked for another version.
Inspecting what you actually get
Do not guess which versions ended up on your classpath. Ask the build tool:
# Maven: resolved dependency tree
mvn dependency:tree
# Maven: the full merged POM, including inherited management
mvn help:effective-pom
# Gradle: resolved dependency graph for the runtime classpath
gradle dependencies --configuration runtimeClasspathThe dependency:tree output shows where a library comes from, and with -Dverbose it also shows versions Maven omitted because of conflicts. This is the first command to run when you see a NoSuchMethodError.
Common mistakes
- Putting a version on a starter. If
spring-boot-starter-webis on a different version than the parent, you get a mixed Boot setup. Leave starters without versions. - Upgrading Spring Framework alone. Boot is built against one Spring Framework line. Change the Boot version to move the whole set.
- Forgetting the repackage execution after importing the BOM. Without it,
mvn packageproduces a plain JAR thatjava -jarcannot run. - Overriding the wrong property. A misspelled property is silently ignored in Maven. Confirm the change with
dependency:tree.
Exercise
Your company requires a corporate parent POM, so you cannot use spring-boot-starter-parent. You import spring-boot-dependencies into dependencyManagement. You set <jackson-bom.version>2.18.2</jackson-bom.version> in your properties, but dependency:tree still shows the old Jackson version. Why, and how do you fix it?
Show answer
An imported BOM does not read your project's properties, so the property override has no effect (it works only when you inherit from spring-boot-starter-parent). Declare the jackson-bom (type pom, scope import) with the version you want in your own dependencyManagement section before the spring-boot-dependencies import, because Maven uses the first declaration it finds. Then re-run dependency:tree to confirm.
Exercise
Why is overriding jackson-bom.version safer than putting a version directly on the jackson-databind dependency?
Show answer
The property changes the version for every artifact in the BOM that uses it, so jackson-databind, jackson-core, and the other Jackson modules stay aligned. A version on one dependency changes only that artifact and can leave its siblings on the managed version, which risks incompatible combinations.