How to force or override the version of a dependency in Maven

Updated: 2023-12-15

Nowadays in our project we have scanner and code analyzers that trigger alerts for CVE security violations.

Often the issues are related to transitive dependencies that come with 3rd part libraries. If the 3rd part library is not quick to fix the issue (a.k.a. update the dependency) our project could be blocked inside our organisation.
It could happen that the 3rd party provider doesn't want or cannot fix update the faulty dependency.

Sometimes is worth to evaluate the possibility to override the transitive dependency ourselves to fix the security vulnerability, e.g.: an upgrade from Tomcat 1.10.14 to Tomcat 1.10.15 that simply fixes a couple of CVE without any API change.

If you want to 'force' a particular version of a dependency and override the 3rd party versions it's worth to read and understand how the dependency management of Maven works:

Update a dependency that doesn't come with Spring Boot

An easy method to force a specific artifact version is to use <dependency-management>:

This example shows hot to 'manually' fix (at your own risk) the CVE-2023-4586 linked to old Netty version.

You are maybe fighting with this security vulnerability using Microsoft SDK Azure libraries ;-)


Updating a dependency that comes with Spring Boot

In this case you are lucky. You need to simply tell Spring which version you want to use without updating the dependency-management part of your pom.xml.

In this example we upgrade the Logback dependency in Spring Boot to the version 1.4.14.

Dependencies in Spring

Spring Boot 3.2.0 delivers by default logback-classic:1.4.11 and logback-core:1.4.11, these 2 dependencies could trigger a Security Alert because of the CVE-2023-6378.

An upgrade to the version 1.4.14 solves the problem.

In your pom.xml

<!-- add this version, the dependency doesn't have to be added to the pom.xml --> 

Now Spring will import the version of the library that you have defined.

There is a complete list of the dependencies and the properties that can be customized in the Spring documentation:

List of dependencies and properties:

Spring properties

Fullstack Angular / Java application quick start guide.
WebApp built by Marco using SpringBoot 3.2.4 and Java 21. Hosted in Switzerland (GE8).