Useful tips to update dependencies in a maven project

Görkem Gök
2 min readJan 21, 2021

Modern projects use lots of dependencies. They are updated due to bug fixes, security patches, and add new features. Updating the dependencies of a project is something that developers should do periodically.

When it comes to java maven is still widely used despite it is called “old school”. Here I shared some commands and techniques that can be used while updating maven dependencies.

Transitive dependencies

Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. [1]

This means that every dependency you put in your pom.xml comes with other dependencies. The pain starts at this point. Two of the dependencies may bring the different versions of the package. Maven resolves the version of the dependencies and transitive dependencies by several different mechanisms and the following command shows the resolved dependency list that you would get when you build the project.

mvn dependency:resolve -Dsort

To write to a file type:

mvn dependency:resolve -Dsort -DoutputFile=project.dep

Output:

...
The following files have been resolved:
antlr:antlr:jar:2.7.7:compile
ch.qos.logback:logback-classic:jar:1.2.3:compile
ch.qos.logback:logback-core:jar:1.2.3:compile
com.adobe.xmp:xmpcore:jar:5.1.3:compile
com.carrotsearch:hppc:jar:0.7.1:compile
com.drewnoakes:metadata-extractor:jar:2.11.0:compile
...

It is very helpful to save the resolved dependencies before updating any versions. You can use this file to compare the version changes after version updates.

$> mvn dependency:resolve -Dsort -DoutputFile=old.dep---update versions or refactor maven pom.xml---$> mvn dependency:resolve -Dsort -DoutputFile=new.dep
$> diff old.dep new.dep
Output:< antlr:antlr:jar:2.7.7:compile
---
> antlr:antlr:jar:3.0.0:compile

Effective pom

The effective-pom goal is used to make visible the POM that results from the application of interpolation, inheritance and active profiles. It provides a useful way of removing the guesswork about just what ends up in the POM that Maven uses to build your…

--

--

Görkem Gök

Developer | Software Craftsmanship Enthusiast | Physicist