tags:

views:

38

answers:

2

In a pom.xml, when specifying a dependency version, what is the difference between LATEST and [0,) ? In my opinion they should be equivalent, but for some dependencies, LATEST does not match any version, whereas [0,) does.

A: 

When you depend on a plugin or a dependency, you can use the a version value of LATEST or RELEASE. LATEST refers to the latest released or snapshot version of a particular artifact, the most recently deployed artifact in a particular repository. RELEASE refers to the last non-snapshot release in the repository. In general, it is not a best practice to design software which depends on a non-specific version of an artifact. If you are developing software, you might want to use RELEASE or LATEST as a convenience so that you don't have to update version numbers when a new release of a third-party library is released. When you release software, you should always make sure that your project depends on specific versions to reduce the chances of your build or your project being affected by a software release not under your control. Use LATEST and RELEASE with caution, if at all.

See, for further information regarding this topic.

Make sure that the artifact you're looking for is present in your local repository.

However, I have to warn you about the LATEST and RELEASE version markers, as the documentation extract says, it is consider a bad practice to work with those. In fact, I think the LATEST and the RELEASE version markers will no longer be supported in Maven 3.X.

My recommendation is that you drop it usage completely and stick to the specific version notation.

EDIT:

Here is a POST that addressed this exact same information, but more thoughtfully.

Thanks to @Pascal Thivent for the observation :) I always include reference to the other StackOverflow questions that deal with the same subject I'm discussing.

StudiousJoseph
See http://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency/1172371#1172371 for the original answer and comments. And thanks for the credits...
Pascal Thivent
Thanks for the observation, no offense. ;)
StudiousJoseph
A: 

In my opinion they should be equivalent, but for some dependencies, LATEST does not match any version, whereas [0,) does.

In theory, LATEST is the latest released or snapshot version (see Rich Seller's excellent answer on the special RELEASE and LATEST versions) so I would indeed expect the same behavior as with the [0,) range. Out of curiosity, can you provide an example where LATEST doesn't match?

That being said, I don't recommend using the LATEST nor RELEASE special versions as they make your build more fragile and harm the build reproducibility (you don't really want your build to suddenly start to fail because of some uncontrolled update). Admittedly, they're considered as a bad idea and references have been removed from the documentation (except from an untranslated part of the German version of the Definitive Guide) and they are no longer supported in Maven 3.x.

You are thus strongly invited to not use them at all (bad practice, deprecated, not supported in the next version).

And I somehow consider the same applies to version ranges (in general), I don't recommend them either as I wrote many times in previous answers or comments. See for example:


Follow-up after comment

Here's an example (among many):

<dependency> 
  <groupId>aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>[0,)</version>
</dependency>

-> matches version 1.5.3 Whereas:

<dependency> 
  <groupId>aspectj</groupId>
  <artifactId>aspectjrt</artifactId>
  <version>LATEST</version>
</dependency>

-> cannot be resolved

I'm not 100% but I don't think this artifact is providing the right maven-metadata.xml for this feature to work. I think metadata should include <release> and <latest> elements like for maven plugins (see for example this maven-metadata.xml). But I wouldn't spend too much time on this for the aforementioned reasons, just forget this LATEST stuff.

Pascal Thivent
Thanks for the answer!Here's an example (among many):<dependency><groupId>aspectj</groupId><artifactId>aspectjrt</artifactId><version>[0,)</version></dependency>-> matches vesrion 1.5.3Whereas:<dependency><groupId>aspectj</groupId><artifactId>aspectjrt</artifactId><version>LATEST</version></dependency>-> cannot be resolved
merejy
@merejy: I'm not sure but I wonder if this project is providing the right [maven-metadata.xml](http://repo1.maven.org/maven2/aspectj/aspectjrt/maven-metadata.xml) for this feature to work. I think metadata should include `<release>` and `<latest>` elements like for maven plugins, e.g. [maven-metadata.xml](http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/maven-metadata.xml). But I wouldn't spend too much time on this for the reasons mentioned above, just forget this LATEST stuff.
Pascal Thivent
I just wanted to solve this mystery :)Thanks a lot for you help!
merejy