views:

546

answers:

2

My maven module A has a dependency on another maven module B provided by other people. When I run "mvn install" under A for the first time, maven downloads B-1.0.jar from a remote repository to my local maven repository. My module A builds fine.

In the mean time, other people are deploying newer B-1.0.jar to the remote repository. When I run "mvn install" under A again, maven does not download the newer B-1.0.jar from the remote repository to my local repository. As a result, my module A build fails due to API changes in B-1.0.jar.

I could manually delete B-1.0.jar from my local repository. Then maven would download the latest B-1.0.jar from the remote repository the next time when I run "mvn install".

My question is how I can automatically let maven download the latest artifacts from a remote repository. I tried to set updatePolicy to "always". But that did not do the trick.

+2  A: 

Maven never re-downloads releases - 1.0 is considered final and new releases should use a new version.

If the module B is still under development, you should use the version 1.0-SNAPSHOT - snapshots are a special Maven version that will check for updates, and when deployed is stored with the timestamp and build number for tracking.

Brett Porter
This is very helpful. SNAPSHOT is just for this purpose.
Richard
A: 

I agree with Brett, above: new releases should use new versions. For your case, snapshots are probably the best solution but something else that might also be helpful is to use dependency version ranges.

Thereby you can specify a version of
(1.0,)
stating that you accept any version greater than 1.0.
or
[1.1.1,1.1.7]
accepting anything between (but not including) versions 1.1.1 and 1.1.7.
The notation follows standard math syntax where

[ = inclusion in the set
( = exclusion from the set

(in school, I always thought of the square brackets as "holding" that element in the set while the softer parenthesis "let it go" from the set)

This can be helpful in cases where your dependencies are still under frequent development and you don't want to rely on new snapshots that might be less stable and more likely to break your code. You can specify the safe ranges and adjust the boundaries up or down, as appropriate, over time

gmale