tags:

views:

107

answers:

2

We're using Maven at work at quite regularly we get the error message "The artifact has no valid ranges". After a long time of Googling and experimenting I realised what this error message means: The artifact does have valid ranges, just too many of them.

For example, my master POM has a dependency on superframework v.1.0 only, but there is also a transitive dependency on superframework v.0.5-0.9.

Until now, whenever I had such a problem I've looked at the (very cryptic) error message and sorta guessed which POM I needed to change - basically a lot of trial an error. The problem is that mvn dependency:tree doesn't work if you have a dependency resolution problem.

The Eclipse plugin sometimes helps a little, but sometimes it is way off.

Any tips on how to resolve these problems?

+2  A: 

This might not be the expected answer but my advice would be to actually not use dependency ranges as they worsen build reproducibility.

I prefer to use fixed versions (which also make dependencies conflicts resolution easier, see the note at the bottom of 9.4.3. Dependency Version Ranges) and use intensively the Dependency Convergence report to manage them.

Pascal Thivent
Thanks for this answer; I will try to get the word out at work.
Lenni
A: 

This isn't a direct answer to my question but rather a word of advice. I learned something new since askin the question: the order in which dependencies are listed in the POM files, much to my surprise, does matter.

So, if you include a dependency on

superframework [0.5,1.5)

it will fetch the latest available version, say 1.1.

If you then have a transitive dependency further down that includes

superframework [0.5, 1.0)

Maven will generate this misleading error, since it will not select anything other than the 1.1 it already has, even though it could just select 0.9 without producing a version conflict. If you swap the order, weirdly, it works.

Am I right in thinking that this is a flaw in Maven's behaviour?

Lenni
This might be related to the way Maven resolves dependencies (and conflicts), see http://docs.codehaus.org/display/MAVEN/Dependency+Mediation+and+Conflict+Resolution. Another good reason to not use ranges IMHO.
Pascal Thivent