140
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 ?

oberlies
  • 11,503
  • 4
  • 63
  • 110
user1844840
  • 1,937
  • 3
  • 16
  • 13
  • Possible duplicate of [How to do remove a projects artifacts from the local maven repo?](https://stackoverflow.com/questions/14631882/how-to-do-remove-a-projects-artifacts-from-the-local-maven-repo) – acm Dec 12 '17 at 16:43

5 Answers5

141

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.

Steve Powell
  • 25,354
  • 8
  • 41
  • 44
  • I don't believe that this works for `.jar`s that were not downloaded from maven central or some other repository. When I run this command it gets rid of all the `.jar`s that automatically downloaded, but when it gets to the `.jar`s that I manually installed, it outputs this error message: `[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:purge-local-repository (default-cli) on project alloy-generator: Failed to refresh project dependencies for: myartifact: required artifacts missing: [ERROR] manually-downloaded-and-installed.jar ...` – stiemannkj1 Jan 15 '14 at 19:24
  • 4
    Actually, after I checked it, I realized that it does uninstall the `.jar`, but it still outputs an error. So for `.jar`s which have been manually installed, I would recommend manually deleting rather than using this method, because maven creates some weird files like `yourjar.jar.lastUpdated` and `yourjar.pom.lastUpdated` which you may need to manually delete anyway. But if maven managed all the dependencies automatically, this is a great way to uninstall the dependencies. – stiemannkj1 Jan 15 '14 at 19:38
  • This approach also requires a maven project in order to run the command. This doesn't appear to work if you ran the install command that the OP specified in the context of say a Gradle build. – jdonmoyer Oct 24 '14 at 13:41
  • You can even remove a complete group with: `dependency:purge-local-repository -Dinclude=de.slr -DresolutionFuzziness=groupId` – membersound May 18 '22 at 08:46
119

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

shareef
  • 9,255
  • 13
  • 58
  • 89
Lagz0ne
  • 1,259
  • 1
  • 8
  • 3
  • 12
    I would delete only the `.m2/repository directory`. A coworker has deleted the .m2 directory before and it causes issues because on our project we have to modify the `settings.xml` file. – Tiris Jan 29 '15 at 17:42
  • 7
    Do note that with deleting the `.m2/repository` directory you will also be deleting all maven plugin files. Whereas using the `purge-local-repository` command you are deleting only dependencies. – collinhaines Jun 30 '16 at 12:06
  • 4
    The directory structure under `.m2/repository` is organized by Maven group ID, so you can just delete the subdirectory corresponding to the artifact you want to remove. – Kevin Krumwiede Aug 23 '16 at 19:33
  • I just deleted the jar file like so rm -riv ./com/oracle/ojdbc7/12.1.0.2/ojdbc7-12.1.0.2.jar – user1561783 Nov 09 '22 at 12:19
25

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.

rob2universe
  • 7,059
  • 39
  • 54
13

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

Abimaran Kugathasan
  • 31,165
  • 11
  • 75
  • 105
  • When I remove the jar that way, it "re-downloads" the jar from the old folder. May be there are references that need to be removed as well. – Antonio Sesto Nov 07 '14 at 14:42
-2

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.