9

This sounds like it should be easy, but I've yet to find an answer. If I install an artifact with mvn install, how do I remove said artifact? I tried using dependency:purge-local-repository, but it only removes the dependencies - not the actual artifact.

Any ideas? I'm using maven 2.2.1 if that helps.

Edit: I'm aware of the similar question, but I'm unsatisfied with the answer of removing my entire .m2 repo just to remove a single SNAPSHOT dependency. Also, as I mentioned, purge-local-repository doesn't work since it only seems to be removing the dependencies and not the actual artifact.

Edit 2: I'm probably not being very clear. Consider this example. I have a SNAPSHOT artifact that is called my-artifact. my-artifact has two dependencies: my-dependency-one and my-dependency-two. I would like to write a script that will delete all three without me having to parse the pom.xml file. In other words, I'd like to purge my-dependency-one, my-dependency-two, AND my-artifact without having to explicitly type into maven that I want to delete my-artifact.

In the answers for the 'duplicate questions' it suggests going in and manually deleting the artifacts from the .m2 repo. That is not an answer to this question given that the script does not knew the group or artifact name when it executes the maven command. I want something similar to dependency:purge-local-repository except that it should not only remove the dependencies, but the artifact itself.

I'm guessing based on the confusion in the comments that this is just not possible. If it isn't that would be an acceptable answer.

Jason Thompson
  • 4,643
  • 5
  • 50
  • 74
  • 2
    on linux `rm -Rf ~/.m2/artifact-location/` – MariuszS Jan 24 '14 at 19:45
  • I saw that one... I don't want to delete my .m2 repo that's more of a hack and will cause me to have to redownload non-snapshots. It's like throwing a nuclear bomb to get rid of a roach. I just want to delete the installed SNAPSHOT artifact and the installed SNAPSHOT dependencies. purge-local-directory only seems to remove dependencies, but not the actual artifact. – Jason Thompson Jan 24 '14 at 19:48
  • 2
    You can delete the exact location of the SNAPSHOT artifact, which would be like ... a sniper fire. – Behe Jan 24 '14 at 19:52
  • I'm trying to automate it in a script if possible. I would prefer something like: mvn removethisartifact Otherwise, I would have to parse out the pom in order to learn where the file is in my .m2 repo. – Jason Thompson Jan 24 '14 at 19:54
  • The [supposedly duplicated question](http://stackoverflow.com/q/15358851/1523648) was explicitly asking for undoing `install:install-file`, so this question is more general. – oberlies Jan 27 '14 at 12:16
  • What do you mean by "I tried using dependency:purge-local-repository, but it only removes the dependencies - not the actual artifact"? I've tried running `dependency:purge-local-repository` on my project just now with the `-DreResolve=false` option. It has successfully removed corresponding folders for all dependencies written in my pom including all files within those folders. – Eugene Evdokimov Jan 27 '14 at 14:11
  • Hi @EugeneEvdokimov, I'll clarify. Consider a project with the artifact foo-bar which has the dependencies foo-baz and foo-qux. When I type `mvn dependency:purge-local-repository` for foo-bar then foo-baz will be uninstalled and foo-qux will be uninstalled, but foo-bar will not. That is the question. What arguments do I type into maven 2.2.1 that would delete all three? My fear is that I will have to manually include the dependency for deletion and thus have to parse the pom file in order to script this (something quite unpleasant in Windows). – Jason Thompson Jan 27 '14 at 19:05
  • Yeah, I see now. The question does not seem to have duplicates on SO. I've posted my solution. – Eugene Evdokimov Jan 27 '14 at 21:30

1 Answers1

5

Here's one way that seems to work (though a bit clumsy).

This removes all dependencies of the project:

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

And this removes the main artifact itself:

mvn dependency:purge-local-repository -DmanualInclude=${project.groupId}:${project.artifactId}:${project.version}

Two steps are required, because

manualIncludes:

The list of dependencies in the form of groupId:artifactId which should BE deleted/purged from the local repository. Note that using this parameter will deactivate the normal process for purging the current project dependency tree. If this parameter is used, only the included artifacts will be purged. The manualIncludes parameter should not be used in combination with the includes/excludes parameters.

(see the plugin doc)

Community
  • 1
  • 1
Eugene Evdokimov
  • 2,220
  • 2
  • 28
  • 33
  • Ah... I didn't realize I could pass in those variables into the command line. I'll give it a try later on tonight and see how it goes. – Jason Thompson Jan 27 '14 at 22:56