Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update maven local repository with newer artifacts from a remote repository?

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.

like image 506
Richard Avatar asked Apr 06 '10 03:04

Richard


2 Answers

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.

like image 88
Brett Porter Avatar answered Sep 17 '22 17:09

Brett Porter


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 (including) versions 1.1.1 and 1.1.7.
The notation follows standard math interval syntax where

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

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

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

like image 33
gMale Avatar answered Sep 21 '22 17:09

gMale