FOSSA Logo

Overriding Dependency Versions and Using Version Ranges in Maven

February 25, 2022 · 2 min read
Java
Maven
Overriding Dependency Versions and Using Version Ranges in Maven

Like most languages, Java only allows a single version of a dependency to be included in a final compiled program. For smaller programs, this is not an issue. But as programs grow larger and larger, they include more and more dependencies, each of which includes its own dependencies. Eventually, picking dependency versions that satisfy the constraints imposed by both the original program and every transitive dependency becomes a tedious and error-prone task. Welcome to dependency hell.

When the first build tools for Java were first created, developers had to manually select the version of dependencies that were included in their builds. However, modern build tools can automatically "solve" for the required version of a build's dependency given that build's requirements. Maven is one such tool.

In this blog, we'll cover several critical aspects of dependency management in Maven: how to declare dependencies, how to override dependency versions, and how to use version ranges.

Declaring Dependencies in Maven

Maven projects are defined in their top-level "pom.xml" file. This file describes a project's name, version, plugins, build steps, and more. This file also includes the project's dependencies:

Subscribe to our newsletter

Get the latest insights on open source license compliance and security delivered to your inbox.