Keep Versions Aligned Under Spring Boot's Dependency Management
Learn what Spring Boot 4.1's dependency management decides for REST Assured, JUnit, Jackson and Hamcrest, why the first imported BOM wins, how to order BOMs so the versions you choose apply, and how to check which versions Maven really resolved.
Adding Spring Boot to a project changes more than the application code. Spring Boot’s dependency management sets the versions of hundreds of libraries, including several a REST Assured suite depends on: JUnit, Jackson and Hamcrest. If its versions are older than the ones the rest of your suite uses, nothing warns you: the tests still pass, on versions you didn’t choose, until a newer feature is missing or a mixed library family fails with an error that seems unrelated. This section has no test class; its lesson is in the module’s pom.xml. In this guide, you’ll order the BOMs so your versions win, and check with Maven what it really resolved.
Level: Advanced · Time: 15 minutes · Part of: Module 11: Spring Boot Integration, section 4
What You’ll Build
You won’t write a test class. You’ll read and change the dependencyManagement of module-11/pom.xml, and check the result with dependency:tree, three times: with the module’s BOM order, with Spring Boot’s BOM moved first, and with one Jackson artifact pinned instead of its whole family.
With the module’s order, Maven resolves the course’s versions:
1
2
3
4
+- org.junit.jupiter:junit-jupiter:jar:6.1.3:test
| \- tools.jackson.core:jackson-databind:jar:3.2.3:compile
| \- tools.jackson.core:jackson-core:jar:3.2.3:compile
\- io.rest-assured:rest-assured:jar:6.3.0:test
When you’re done, the module’s 16 tests pass on the versions you chose:
1
2
[INFO] Tests run: 16, Failures: 0, Errors: 0, Skipped: 0
[INFO] BUILD SUCCESS
In this guide, you will:
- Order the BOMs.
- Check what Maven resolved.
- See a mixed family fail.
What You Need
- About 15 minutes
- JDK 26 or later
- Maven 3.9 or later
- An IDE (IntelliJ IDEA, VS Code or Eclipse)
- Knowledge: you know what Maven’s
dependencyManagementdoes, and you’ve run the module’s tests in Test Spring Boot on a Random Port With REST Assured and Real Tokens.
How to Complete This Guide
You can work through this guide in one of two ways:
- Build it step by step: open
module-11/pom.xml, follow every heading below, and make each change yourself. Put the file back as it was afterwards. - Skip ahead: open the finished file (
module-11/pom.xml) and read along. You can run the commands at any time with those in Run the Tests.
Get the code: if you haven’t cloned the examples repository yet, follow the steps in Test a Spring Controller With RestAssuredMockMvc in Standalone Mode.
Out of scope: this guide uses Maven. Gradle’s platforms work differently, and aren’t covered.
Understand Version Alignment
The problem. A REST Assured suite and Spring Boot both care about the versions of JUnit, Jackson and Hamcrest, and they don’t always agree. Spring Boot’s choice applies unless you take care, and it applies silently.
The concept. A BOM (bill of materials) is a Maven POM that only lists versions, in its dependencyManagement. You import it into your own dependencyManagement:
1
2
3
4
5
6
7
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
After that, dependencies the BOM manages can be declared without a version, and transitive dependencies are pulled to the managed version too. Three rules decide which version wins:
- A version you declare yourself, in a dependency or your own
dependencyManagement, beats any imported BOM. - Between imported BOMs, the first one declared wins. A later BOM can’t override an earlier one.
- A library no BOM manages gets the version its dependants ask for, by Maven’s “nearest wins” rule.
Spring Boot 4.1.2 manages several libraries this guide uses, some at older versions:
| Library | Spring Boot 4.1.2 manages | This guide uses |
|---|---|---|
| JUnit | 6.0.3 | 6.1.3 |
| Jackson 3 | 3.1.7 | 3.2.3 |
| Hamcrest | 3.0 | 3.0 |
| REST Assured | not managed | 6.3.0 |
When to use each. Import the BOM of every library family whose version you choose, before Spring Boot’s, and let Spring Boot’s BOM manage the rest. Never pin a single artifact of a family.
Import the BOMs you want to win first, and check the result with Maven.
Meet the Build Under Test
module-11 is a Spring Boot 4.1.2 application with these dependencies:
| Dependency | Scope | Version from |
|---|---|---|
spring-boot-starter-webmvc | compile | Spring Boot’s BOM |
spring-boot-starter-security-oauth2-resource-server | compile | Spring Boot’s BOM |
spring-boot-starter-webmvc-test | test | Spring Boot’s BOM |
spring-boot-starter-security-oauth2-resource-server-test | test | Spring Boot’s BOM |
io.rest-assured:spring-mock-mvc | test | rest-assured-bom |
JUnit and Jackson arrive transitively, through Spring Boot’s starters and REST Assured. Their versions are what this guide is about.
The things you’ll check:
- The resolved versions of
junit-jupiter,jackson-databind,jackson-coreandrest-assured. - Whether the module’s 16 tests still pass.
Order the BOMs
Import the Course’s BOMs First
Goal: make JUnit’s, REST Assured’s and Jackson’s BOMs win over Spring Boot’s.
The module’s dependencyManagement imports four BOMs, in this order:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<dependencyManagement>
<dependencies>
<!-- Lesson 11.4: when several imported BOMs manage the same artifact, the first one declared wins.
Spring Boot 4.1.2 manages JUnit 6.0.3 and Jackson 3.1.7; we want the course's JUnit 6.1.3, Jackson 3.2.3
and REST Assured 6.3.0, so their BOMs come before Spring Boot's. -->
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>6.1.3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-bom</artifactId>
<version>6.3.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>tools.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
What’s happening:
- JUnit’s, REST Assured’s and Jackson’s BOMs come first, so for those families they win.
- Spring Boot’s BOM comes last, and still manages everything else, so Spring’s own dependencies stay consistent with each other.
- Each import is a whole family’s BOM, not one artifact: Jackson and JUnit are many artifacts that must have exactly the same version.
Checkpoint: nothing to run yet; the next step asks Maven what these imports resolve to.
The course’s parent POM imports the same three BOMs, and that isn’t enough. With Spring Boot’s BOM first in the module, JUnit and Jackson dropped to Spring Boot’s versions anyway. The module repeats the imports, ahead of Spring Boot’s.
Check What Maven Resolved
Run dependency:tree
Goal: see the versions Maven really chose.
Run this command from the repository root:
1
2
mvn -f module-11/pom.xml dependency:tree \
-Dincludes='org.junit.jupiter:junit-jupiter-api,org.junit.platform:junit-platform-engine,tools.jackson.core:*,io.rest-assured:*,org.hamcrest:hamcrest'
You should see a result similar to the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
com.javanibble:module-11:jar:0.0.1-SNAPSHOT
+- org.springframework.boot:spring-boot-starter-webmvc:jar:4.1.2:compile
| \- org.springframework.boot:spring-boot-starter-jackson:jar:4.1.2:compile
| \- org.springframework.boot:spring-boot-jackson:jar:4.1.2:compile
| \- tools.jackson.core:jackson-databind:jar:3.2.3:compile
| \- tools.jackson.core:jackson-core:jar:3.2.3:compile
+- io.rest-assured:spring-mock-mvc:jar:6.3.0:test
| \- io.rest-assured:spring-commons:jar:6.3.0:test
+- org.junit.jupiter:junit-jupiter:jar:6.1.3:test
| +- org.junit.jupiter:junit-jupiter-api:jar:6.1.3:test
| \- org.junit.jupiter:junit-jupiter-engine:jar:6.1.3:test
| \- org.junit.platform:junit-platform-engine:jar:6.1.3:test
\- io.rest-assured:rest-assured:jar:6.3.0:test
+- org.hamcrest:hamcrest:jar:3.0:test
+- io.rest-assured:json-path:jar:6.3.0:test
| \- io.rest-assured:rest-assured-common:jar:6.3.0:test
\- io.rest-assured:xml-path:jar:6.3.0:test
What’s happening:
-Dincludes=..limits the tree to the artifacts you care about, with their paths.- Jackson is 3.2.3, both
jackson-databindandjackson-core, and the JUnit Jupiter and Platform artifacts are all 6.1.3. - Every REST Assured module is 6.3.0, from
rest-assured-bom.
Checkpoint: your output matches the course’s versions: JUnit 6.1.3, Jackson 3.2.3 and REST Assured 6.3.0.
Move Spring Boot’s BOM First
Goal: see what happens when Spring Boot’s BOM wins.
Move the spring-boot-dependencies import to the top of dependencyManagement, and run the same command again. The changed lines:
1
2
3
4
5
6
| \- tools.jackson.core:jackson-databind:jar:3.1.7:compile
| \- tools.jackson.core:jackson-core:jar:3.1.7:compile
+- org.junit.jupiter:junit-jupiter:jar:6.0.3:test
| +- org.junit.jupiter:junit-jupiter-api:jar:6.0.3:test
| \- org.junit.jupiter:junit-jupiter-engine:jar:6.0.3:test
| \- org.junit.platform:junit-platform-engine:jar:6.0.3:test
What’s happening:
- Spring Boot’s BOM is now the first to manage JUnit and Jackson, so its versions win: Jackson 3.1.7 and JUnit 6.0.3.
- REST Assured stays at 6.3.0, because Spring Boot 4 doesn’t manage it at all.
- The build gives no warning. With this order, all 16 tests in the module still passed, on versions nobody chose.
Checkpoint: your output shows 3.1.7 and 6.0.3. Move the import back to the bottom before you go on.
A passing build proves nothing about versions. Spring Boot’s older JUnit and Jackson ran all 16 tests green; the first sign would have been a JUnit 6.1 feature or a Jackson 3.2 fix that wasn’t there. Run
dependency:treeafter every Spring Boot upgrade.
See a Mixed Family Fail
Pin One Artifact Instead of the Family
Goal: see why a whole BOM matters, by pinning one Jackson artifact.
In dependencyManagement, replace the jackson-bom import with a version for jackson-databind alone:
1
2
3
4
5
<dependency>
<groupId>tools.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>3.2.3</version>
</dependency>
Run dependency:tree with -Dincludes='com.fasterxml.jackson.core:jackson-annotations,tools.jackson.core:*':
1
2
3
\- tools.jackson.core:jackson-databind:jar:3.2.3:compile
+- com.fasterxml.jackson.core:jackson-annotations:jar:2.21:compile
\- tools.jackson.core:jackson-core:jar:3.1.7:compile
What’s happening:
- Your declared version wins for
jackson-databind, by the first rule. Everything else in the family falls back to Spring Boot’s BOM:jackson-core3.1.7. - Jackson 3 keeps
jackson-annotationsunder its old group,com.fasterxml.jackson.core, with 2.x versions.jackson-bom3.2.3 manages it at 2.22; Spring Boot’s at 2.21. - The family is now mixed: one artifact at 3.2.3, the others at older versions.
Checkpoint: your tree shows the mixed versions. The next section runs the tests with them.
Run the Tests
Put module-11/pom.xml back as it was, and run the module’s tests from the repository root:
1
mvn test -pl module-11
You should see a result similar to the following, after Spring Boot’s start-up logs:
1
2
3
[INFO] Tests run: 16, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] BUILD SUCCESS
Make a Test Fail
Pin jackson-databind alone again, as in the previous step, and run mvn test -pl module-11. You should see a result similar to the following:
1
2
3
4
5
6
7
[ERROR] com.javanibble.module_11.section_01.StandaloneMockMvcTest.listAccounts -- Time elapsed: 0.371 s <<< ERROR!
jakarta.servlet.ServletException: Handler dispatch failed: java.lang.NoClassDefFoundError: com/fasterxml/jackson/annotation/JsonApplyView
...
[ERROR] com.javanibble.module_11.section_03.RandomPortServerTest.aReaderCanListAccounts -- Time elapsed: 0.175 s <<< FAILURE!
java.lang.AssertionError:
1 expectation failed.
Expected status code <200> but was <500>.
Nine of the 16 tests failed: three errors in each MockMvc class, and three failures in the random-port class, where the same error became a 500. jackson-databind 3.2.3 needs an annotation that jackson-annotations 2.21 doesn’t have. Nothing in the messages mentions versions, which is what makes a mixed family hard to diagnose.
Put the jackson-bom import back and run the tests once more to confirm they pass.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
NoClassDefFoundError or NoSuchMethodError in a Jackson class | A mixed Jackson family | Import jackson-bom instead of pinning one artifact |
An older JUnit or Jackson in dependency:tree | Spring Boot’s BOM comes first | Import the BOMs you want to win before it |
| Tests aren’t discovered after an upgrade | JUnit Jupiter and Platform at different versions | Import junit-bom |
IllegalStateException explaining how to align REST Assured’s versions | An older rest-assured-common on the classpath | Import rest-assured-bom |
| A version property in your POM changes nothing | Nothing uses the property, or its BOM loses | Check with dependency:tree |
REST Assured 6.3 detects the last case itself: according to its changelog,
RestAssured,RestAssuredMockMvcandRestAssuredWebTestClientfail with anIllegalStateExceptionthat explains how to align the versions when an olderrest-assured-commonis on the classpath, instead of aNoClassDefFoundError.
Try It Yourself
Exercise 1: Find the Annotations Version
With the module’s pom.xml as it is, run dependency:tree for com.fasterxml.jackson.core:jackson-annotations, and work out which BOM chose its version.
Hint
Use -Dincludes='com.fasterxml.jackson.core:jackson-annotations'. Compare the version with the one in the mixed-family tree above.
Solution
1
mvn -f module-11/pom.xml dependency:tree -Dincludes='com.fasterxml.jackson.core:jackson-annotations'
1
2
3
4
5
6
com.javanibble:module-11:jar:0.0.1-SNAPSHOT
\- org.springframework.boot:spring-boot-starter-webmvc:jar:4.1.2:compile
\- org.springframework.boot:spring-boot-starter-jackson:jar:4.1.2:compile
\- org.springframework.boot:spring-boot-jackson:jar:4.1.2:compile
\- tools.jackson.core:jackson-databind:jar:3.2.3:compile
\- com.fasterxml.jackson.core:jackson-annotations:jar:2.22:compile
It’s 2.22, from jackson-bom 3.2.3, which comes before Spring Boot’s BOM. With only jackson-databind pinned, it was Spring Boot’s 2.21. A BOM manages artifacts outside its own group too.
Exercise 2: Prove Spring Boot Doesn’t Manage REST Assured
Look in Spring Boot’s BOM for REST Assured. Find spring-boot-dependencies-4.1.2.pom in your local Maven repository, and search it for rest-assured.
Hint
Imported BOMs are in ~/.m2/repository, under their group id as directories: org/springframework/boot/spring-boot-dependencies/4.1.2.
Solution
1
grep -c rest-assured ~/.m2/repository/org/springframework/boot/spring-boot-dependencies/4.1.2/spring-boot-dependencies-4.1.2.pom
The count is 0. The same file has <junit-jupiter.version>6.0.3</junit-jupiter.version>, <jackson-bom.version>3.1.7</jackson-bom.version> and <hamcrest.version>3.0</hamcrest.version>, the versions in the table in Understand Version Alignment.
Summary
You ordered the module’s BOMs so the course’s JUnit, Jackson and REST Assured versions win, checked them with dependency:tree, and saw what goes wrong otherwise: Spring Boot’s older versions, silently, and a mixed Jackson family that failed 9 of 16 tests.
- Spring Boot 4.1.2 manages JUnit 6.0.3 and Jackson 3.1.7, older than this guide’s, and doesn’t manage REST Assured at all.
- Between imported BOMs, the first one declared wins; a version you declare yourself beats them all.
- Import JUnit’s, REST Assured’s and Jackson’s BOMs before Spring Boot’s, in the module itself.
- Import whole BOMs, never one artifact of a family: a mixed family fails with errors that don’t mention versions.
- A passing build proves nothing about versions; check with
dependency:tree, especially after an upgrade.
Here are the commands you used in this guide:
1
2
3
mvn -f module-11/pom.xml dependency:tree -Dincludes='org.junit.jupiter:junit-jupiter-api,org.junit.platform:junit-platform-engine,tools.jackson.core:*,io.rest-assured:*,org.hamcrest:hamcrest'
mvn -f module-11/pom.xml dependency:tree -Dincludes='com.fasterxml.jackson.core:jackson-annotations'
mvn test -pl module-11
What’s Next
Next: you’ve finished Module 11. Continue with Module 12: Real Infrastructure with Testcontainers, starting with Test With Real OAuth 2.0 Tokens From Keycloak and Testcontainers, which replaces the test key with a real authorization server.
The code:
- The module’s build:
module-11/pom.xml - The course’s parent build:
pom.xml - The code and run commands for this module: Module 11 README
Go deeper:
- Maven: Introduction to the Dependency Mechanism, for importing BOMs and “nearest wins”.
- Spring Boot: Dependency Versions, for everything Spring Boot manages.
- REST Assured changelog, for the 6.3 version check.
Related guides:
- Map Responses to Java Records in REST Assured, for the Jackson 3 mapping that a mixed family breaks.
- Test a Spring Controller With RestAssuredMockMvc in Standalone Mode, for the module’s first tests.
