In Maven, dependencies are usually set up like this:
<dependency>
<groupId>wonderful-inc</groupId>
<artifactId>dream-library</artifactId>
<version>1.2.3</version>
</dependency>
Now, if you are working with libraries that have frequent releases, constantly updating the <version> tag can be somewhat annoying. Is there any way to tell Maven to always use the latest available version (from the repository)?
The truth is even in 3.x it still works, surprisingly the projects builds and deploys. But the LATEST/RELEASE keyword causing problems in m2e and eclipse all over the place, ALSO projects depends on the dependency which deployed through the LATEST/RELEASE fail to recognize the version.
It will also causing problem if you are try to define the version as property, and reference it else where.
So the conclusion is use the versions-maven-plugin if you can.
NOTE:
This answer applies to Maven 2 only! The mentioned
LATEST
andRELEASE
metaversions have been dropped in Maven 3 "for the sake of reproducible builds", over 6 years ago. Please refer to this Maven 3 compliant solution.If you always want to use the newest version, Maven has two keywords you can use as an alternative to version ranges. You should use these options with care as you are no longer in control of the plugins/dependencies you are using.
See the POM Syntax section of the Maven book for more details. Or see this doc on Dependency Version Ranges, where:
[
&]
) means "closed" (inclusive).(
&)
) means "open" (exclusive).Here's an example illustrating the various options. In the Maven repository, com.foo:my-foo has the following metadata:
If a dependency on that artifact is required, you have the following options (other version ranges can be specified of course, just showing the relevant ones here):
Declare an exact version (will always resolve to 1.0.1):
Declare an explicit version (will always resolve to 1.0.1 unless a collision occurs, when Maven will select a matching version):
Declare a version range for all 1.x (will currently resolve to 1.1.1):
Declare an open-ended version range (will resolve to 2.0.0):
Declare the version as LATEST (will resolve to 2.0.0) (removed from maven 3.x)
Declare the version as RELEASE (will resolve to 1.1.1) (removed from maven 3.x):
Note that by default your own deployments will update the "latest" entry in the Maven metadata, but to update the "release" entry, you need to activate the "release-profile" from the Maven super POM. You can do this with either "-Prelease-profile" or "-DperformRelease=true"
It's worth emphasising that any approach that allows Maven to pick the dependency versions (LATEST, RELEASE, and version ranges) can leave you open to build time issues, as later versions can have different behaviour (for example the dependency plugin has previously switched a default value from true to false, with confusing results).
It is therefore generally a good idea to define exact versions in releases. As Tim's answer points out, the maven-versions-plugin is a handy tool for updating dependency versions, particularly the versions:use-latest-versions and versions:use-latest-releases goals.
The dependencies syntax is located at the Dependency Version Requirement Specification documentation. Here it is is for completeness:
In your case, you could do something like
<version>[1.2.3,)</version>
Sometimes you don't want to use version ranges, because it seems that they are "slow" to resolve your dependencies, especially when there is continuous delivery in place and there are tons of versions - mainly during heavy development.
One workaround would be to use the versions-maven-plugin. For example, you can declare a property:
and add the versions-maven-plugin to your pom file:
Then, in order to update the dependency, you have to execute the goals:
If there is a version newer than 1.1.1, it will tell you:
Now I know this topic is old, but reading the question and the OP supplied answer it seems the Maven Versions Plugin might have actually been a better answer to his question:
In particular the following goals could be of use:
The following other goals are also provided:
Just thought I'd include it for any future reference.
Please take a look at this page (section "Dependency Version Ranges"). What you might want to do is something like
These version ranges are implemented in Maven2.