Force re-download of release dependency using Maven

Maven 2MavenDependency ManagementMaven Dependency-Plugin

Maven 2 Problem Overview


I'm working on a project with dependency X. X, in turn, depends on Y.

I used to explicitly include Y in my project's pom. However, it was not used and to make things cleaner, I instead added it to X's pom as a dependency. X is marked as a release dependency.

The problem is that after removing Y from my project's pom and adding it to X's pom, my project isn't picking it up on mvn -U clean package. I know -U update snapshots but not releases.

So, without deleting the ~/.m2/repository directory how can I force a re-download of X's pom? Also, I tried running dependency:purge-local-repository and it didn't work either.

Maven 2 Solutions


Solution 1 - Maven 2

You cannot make Maven re-download dependencies, but what you can do instead is to purge dependencies that were incorrectly downloaded using mvn dependency:purge-local-repository

See: http://maven.apache.org/plugins/maven-dependency-plugin/purge-local-repository-mojo.html

This looks up the list of all transitive dependencies of the current project, deletes them, then redownloads them. You can even add it as a plugin into your pom if you want to run it with every build.

Solution 2 - Maven 2

I just deleted my ~/.m2/repository and that forced a re-download ;)

Solution 3 - Maven 2

Based on Ali Tokmen answer. I managed to force delete a single specific local dependency with the following command:

mvn dependency:purge-local-repository -DmanualInclude=com.skyfish:utils

With this, it removes utils from my .m2/repository and it always re-download the utils JAR dependency when I proceed to run mvn clean install. If you want something more programmatic possibly also see the -Dinclude=... option.

Solution 4 - Maven 2

I think following command may help you!


mvn -U clean install

Solution 5 - Maven 2

mvn clean install -U

-U means force update of dependencies.

If you want to update a single dependency without clean or -U you could just remove it from your local repo and then build.

Solution 6 - Maven 2

Project right click-> Maven -> Update Project and check the checkboxes as in the screen shot. It will update releases as well :)

enter image description here

Solution 7 - Maven 2

If you know the group id of X, you can use this command to redownload all of X and it's dependencies

mvn clean dependency:purge-local-repository -DresolutionFuzziness=org.id.of.x

It does the same thing as the other answers that propose using dependency:purge-local-repository, but it only deletes and redownloads everything related to X.

Solution 8 - Maven 2

When you added it to X, you should have incremented X's version number i.e X-1.2
Then X-1.2 should have been installed/deployed and you should have changed your projects dependency on X to be dependent on the new version X-1.2

Solution 9 - Maven 2

If you really want to force-download all dependencies, you can try to re-initialise the entire maven repository. Like in this article already described, you could use:

mvn -Dmaven.repo.local=$HOME/.my/other/repository clean install

Solution 10 - Maven 2

Just delete ~/.m2/repository...../actual_path where the invalid LOC is coming as it forces to re-download the deleted jar files. Dont delete the whole repository folder instead delete the specific folder from where the error is coming.

Solution 11 - Maven 2

Deleting the ~/.m2/repository will solve your problem. But, if you still need to keep the old ~/.m2/repository you can just change the maven local path temporarily.

If you are working on IntelliJ just go to Maven Settings and change the Local Repository path to somewhere else. You may need to tick the override checkbox near there.

enter image description here

Solution 12 - Maven 2

Go to build path... delete existing maven library u added... click add library ... click maven managed dependencies... then click maven project settings... check resolve maven dependencies check box..it'll download all maven dependencies

Solution 13 - Maven 2

Most answers provided above would solve the problem.

But if you use IntelliJ and want it to just fix it for you automatically, go to Maven Settings.

Build,Execution, Deployment -> Build Tools -> Maven

enter image description here

Disable Work Offline

Enable Always update snapshots (Switch when required)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvolniView Question on Stackoverflow
Solution 1 - Maven 2Ali TokmenView Answer on Stackoverflow
Solution 2 - Maven 2Ryan AngillyView Answer on Stackoverflow
Solution 3 - Maven 2skyfishView Answer on Stackoverflow
Solution 4 - Maven 2RichardView Answer on Stackoverflow
Solution 5 - Maven 2ArpitBoraView Answer on Stackoverflow
Solution 6 - Maven 2nanosoftView Answer on Stackoverflow
Solution 7 - Maven 2smac89View Answer on Stackoverflow
Solution 8 - Maven 2crowneView Answer on Stackoverflow
Solution 9 - Maven 2Bart den HaakView Answer on Stackoverflow
Solution 10 - Maven 2Saurabh OzaView Answer on Stackoverflow
Solution 11 - Maven 2Tharindu SathischandraView Answer on Stackoverflow
Solution 12 - Maven 2SagaramVijayView Answer on Stackoverflow
Solution 13 - Maven 2Caffeinated CoderView Answer on Stackoverflow