Dependency Versioning Strategies
About
In Maven, dependency versioning determines which version of a library or framework is used in our project. Proper versioning is essential for
Ensuring compatibility with other dependencies.
Preventing breaking changes from new versions.
Managing security fixes and performance improvements.
Since dependencies evolve, we must have a strategy to manage their versions effectively.
Types of Dependency Versioning in Maven
1. Fixed Versioning (Explicit Version)
We manually specify a fixed version of a dependency in
pom.xml
.Ensures stability but requires manual updates.
Example:
2. Floating Versioning (Using LATEST and RELEASE)
LATEST: Uses the latest available version (including SNAPSHOT versions).
RELEASE: Uses the latest stable release (non-SNAPSHOT).
Example:
Imagine the following versions exist in Maven Central:
If we specify
LATEST
, it selects1.3.0-SNAPSHOT
because it's the newest, even if it's unstable.If we specify
RELEASE
, it selects1.2.0
because it's the latest stable release.
3. Version Ranges
Allows specifying a range of acceptable versions.
Syntax Examples:
[1.5,2.0]
→ Accepts versions 1.5 to 2.0 (inclusive).[1.5,2.0)
→ Accepts 1.5 to 2.0 (excluding 2.0).(,1.5]
→ Accepts any version up to 1.5 (inclusive).[1.0,]
→ Accepts 1.0 and all later versions.
Example:
4. Dependency Management with BOM (Bill of Materials)
Instead of specifying versions in every dependency, a BOM centralizes versioning.
Helps keep versions consistent across large projects.
Example:
Now, dependencies inside the project inherit the BOM’s versions:
5. SNAPSHOT Versions (For Development)
Used for ongoing development versions before an official release.
Example:
Last updated
Was this helpful?