How to remove jar file from local maven repository which was added with install:install-file?

Maven

Maven Problem Overview


mvn install:install-file -Dfile=phonegap-1.1.0.jar -DgroupId?=phonegap -DartifactId?=phonegap -Dversion=1.1.0 -Dpackaging=jar

I use above command to install local jar into maven local repo. Now I have got the dependency from maven repo. I want to remove this from local repo. How to clean it ?

Maven Solutions


Solution 1 - Maven

Although deleting files manually works, there is an official way of removing dependencies of your project from your local (cache) repository and optionally re-resolving them from remote repositories.

The goal purge-local-repository, on the standard Maven dependency plugin, will remove the locally installed dependencies of this project from your cache. Optionally, you may re-resolve them from the remote repositories at the same time.

This should be used as part of a project phase because it applies to the dependencies for the containing project. Also transitive dependencies will be purged (locally) as well, by default.

If you want to explicitly remove a single artifact from the cache, use purge-local-repository with the manualInclude parameter. For example, from the command line:

mvn dependency:purge-local-repository -DmanualInclude="groupId:artifactId, ..."

The documentation implies that this does not remove transitive dependencies by default. If you are running with a non-standard cache location, or on multiple platforms, these are more reliable than deleting files "by hand".

The full documentation is in the maven-dependency-plugin spec.

Note: Older versions of the maven dependency plugin had a manual-purge-local-repository goal, which is now (version 2.8) implied by the use of manualInclude. The documentation for manualIncludes (with an s) should be read as well.

Solution 2 - Maven

While there is a maven command you can execute to do this, it's easier to just delete the files manually from the repository.

Like this on windows Documents and Settings\your username\.m2 or $HOME/.m2 on Linux

Solution 3 - Maven

At least on the current maven version you need to add the switch -DreResolve=false if you intend to remove the dependencies from your local repo without re-downloading them.

mvn dependency:purge-local-repository -DreResolve=false

removes the dependencies without downloading them again.

Solution 4 - Maven

Delete every things (jar, pom.xml, etc) under your local ~/.m2/repository/phonegap/1.1.0/ directory if you are using a linux OS.

Solution 5 - Maven

I faced the same problem, went through all the suggestions above, but nothing worked. Finally I deleted both .m2 and .ivy folder and it worked for me.

Solution 6 - Maven

  1. cd ~/.m2
  2. git init
  3. git commit -am "some comments"
  4. cd /path/to/your/project
  5. mvn install
  6. cd ~/.m2
  7. git reset --hard

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
Questionuser1844840View Question on Stackoverflow
Solution 1 - MavenSteve PowellView Answer on Stackoverflow
Solution 2 - MavenLagz0neView Answer on Stackoverflow
Solution 3 - Mavenrob2universeView Answer on Stackoverflow
Solution 4 - MavenAbimaran KugathasanView Answer on Stackoverflow
Solution 5 - MavenNagesh VashistView Answer on Stackoverflow
Solution 6 - MavenKent YaoView Answer on Stackoverflow