Maven's Versions Plugin Updates All Your Dependencies With a Single Command
It’s a good habit to use the latest versions of the dependencies you
use. Not only because the updated version might contain new features or
better performance (one can hope), but also because bugs are fixed and
security issues are tackled. If you go about it by hand, however,
updating dependencies is a boring and tedious task. Luckily for us,
there is the Maven versions
plugin to help us.
Table of Contents
- Check Which Dependencies/Plugins/Properties Need Updating
- Update Parent
- Update To Latest Versions
- Update a Particular Property with Bounds
- Conclusion
- Reference
Check Which Dependencies/Plugins/Properties Need Updating
If you need a report on which dependencies, plugins or properties used for versioning can be upgraded, run one of these:
versions:display-dependency-updates
scans a project’s dependencies and produces a report of those dependencies which have newer versions available.
versions:display-plugin-updates
scans a project’s plugins and produces a report of those plugins which have newer versions available, taking care of Maven version prerequisites.
versions:display-property-updates
scans a project and produces a report of those properties which are used to control artifact versions and which properties have newer versions available.
Update Parent
If you have a parent section, the following command updates the version to the latest available:
$ mvn versions:update-parent
Update To Latest Versions
To upgrade all your dependencies to the latest versions, use:
$ mvn versions:use-latest-versions
Update a Particular Property with Bounds
To upgrade dependencies that get their version from the <properties>
section of your POM to version that has bounds:
$ mvn versions:update-property \
-Dproperty='cucumber.version' \
-DnewVersion='(,4.99]'
In this case, the lower bound is unspecified (and exclusive as
indicated by the (
) and the upper bound in 4.99
inclusive. You can
tweak -DnewVersion
to your
liking.
Conclusion
The Maven versions
plugin makes it easy for us the see which
dependencies are outdated and can even update the dependencies for us
with a single command. After updating, don’t forget to run your test
suite and run the application to make sure nothing broke!
Reference
This has been tested on MacOS with the following Maven and versions
versions:
$ mvn --version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/Cellar/maven/3.6.3_1/libexec
Java version: 13.0.2, vendor: N/A, runtime: /usr/local/Cellar/openjdk/13.0.2+8_2/libexec/openjdk.jdk/Contents/Home
Default locale: en_NL, platform encoding: UTF-8
OS name: "mac os x", version: "10.15.4", arch: "x86_64", family: "mac"
$ mvn help:describe -Dplugin=versions -Dminimal | grep '^Version: '
Version: 2.7
The documentation can be found here.