Maven - dependency updates

Available Maven dependency updates:

https://www.mojohaus.org/versions/versions-maven-plugin/index.html

To simply know if and how we can update our project, the right tool for the job is this command:

mvn versions:display-dependency-updates

This command checks and shows if there are updates to the versions of the dependencies.

The problem with this approach is that it also shows updates for the nested dependencies - that may or may not be too useful.

Available updates to properties versions

In projects with a large number of dependancies, we sometimes keep our versions in a properties section.

e.g.

<properties>
    <assertj.version>3.15.0</assertj.version>
    <aws-sdk.version>1.11.763</aws-sdk.version>
    <cxf.version>3.3.6</cxf.version>

In the case where you are only interested in updates to those versions, you can use the following command

mvn versions:display-property-updates

This gives a more condensed view and only returns the versions you need to update in the properties section.

Maven How to use a specific version of dependency

How to force a maven project to use older version of a dependency instead of a new version from another dependency?

You can exclude the cyclic dependencies by using the <exclusions> tag in your pom.xml like this:

<dependency>
  <groupId>sample.ProjectB</groupId>
  <artifactId>Project-B</artifactId>
  <version>1.0-SNAPSHOT</version>
  <exclusions>
    <exclusion>
      <groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
      <artifactId>Project-E</artifactId>
    </exclusion>
  </exclusions>
</dependency>

Reading material:

  1. https://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
  2. Spring Boot starter parents

Links to this note