Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Force Update Snapshot Dependencies

Tags:

Here is the result of mvn -version:

Apache Maven 3.0.4 (r1232337; 2012-01-17 00:44:56-0800)
Maven home: /usr/share/maven
Java version: 1.7.0_67, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.5", arch: "x86_64", family: "mac"

Suppose I have a snapshot dependency:

<dependency>
    <groupId>org.puzzled</groupId>
    <artifactId>foo</artifactId>
    <version>1.0.4-SNAPSHOT</version>
</dependency>

I have a downloaded copy of that snapshot in my local repo. But then other developers have made improvements and there is an update to the foo-1.0.4-SNAPSHOT.jar. I want to issue Maven an executive order to update that dependency by downloading it from a remote repository.

According to the response to this and many other questions on SO, if I do

mvn clean -U package

it should just (re)download all the dependencies. Right? That is not what happens. It downloads metadata for snapshot dependencies, deduces (and wrongly, at that) that no updating is required. I have to delete the associated subdirectory in my local .m2 repository for Maven to update a snapshot release from the remote repo, even with the -U flag.

Is this a bug, or am I missing something?

like image 937
dgorur Avatar asked Sep 22 '14 21:09

dgorur


People also ask

How do I force Maven to download dependencies in Eclipse?

Via the Maven index, you can search for dependencies, select them and add them to your pom file. To download the index, select Windows > Preferences > Maven and enable the Download repository index updates on startup option. After changing this setting, restart Eclipse. This triggers the download of the Maven index.

How do I force Maven to download?

Force maven to fetch dependencies from the remote repository while building the project. We can use -U/--update-snapshots flag when building a maven project to force maven to download dependencies from the remote repository.


2 Answers

mvn clean install -U

-U means force update of dependencies.

like image 168
jordiburgos Avatar answered Oct 21 '22 16:10

jordiburgos


Is it possible that the repository is publishing your foo using a non-unique SNAPSHOT name?

This blog entry explains nicely the difference between a unique and non-unique SNAPSHOT artifact.

Essentially, it's non-unique if the artifact metadata appears on nexus as foo-1.0.4-SNAPSHOT.jar. It's unique if it appears as foo-1.0.4-20160122.172609-36.jar.

You can only publish unique snapshot artifacts in Maven 3, but still resolve old timestamped non-unique snapshots... but it's pretty iffy. Taking a look at the ancient doc, it seems that there's some unclear and vague interaction between the filesystem date, and the metadata.xml on both local and remote machines.

Essentially: (1) Try to make sure that your SNAPSHOT dependencies are published with unique artifacts, and (2) if they aren't, don't depend on new SNAPSHOTs being detected. Use mvn dependency:purge-local-repository with appropriate includes to remove the old SNAPSHOTs from your local m2 instead.

like image 37
Ryan Skraba Avatar answered Oct 21 '22 18:10

Ryan Skraba