Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I execute the opposite of mvn install from a script that does not know the name of the artifact or group ID of the artifact being uninstalled? [duplicate]

Tags:

maven-2

maven

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.

like image 414
Jason Thompson Avatar asked Jan 24 '14 19:01

Jason Thompson


People also ask

How do I undo an Maven install?

If you need to remove Maven from your computer, all you need to do is delete your Maven installation directory and remove the environment variables. You will also want to delete the ~/. m2 directory as it contains your local repository.

Which command is used to run the clean life cycle followed by verify install and package with Maven?

When you call mvn deploy , mvn will also execute every lifecycle phase before deploy , in order: validate , compile , test , package , verify , install .

What is the difference between mvn clean install and mvn clean package?

mvn package: Creates JAR or WAR file for the project to convert it into a distributable format. mvn install: Deploys the packaged JAR/ WAR file to the local repository.

What is the difference between mvn install and mvn deploy?

mvn:install copies your packaged Maven module to your local repository (by default, in ~/. m2/repository ), to be accessed by other local Maven builds. mvn:deploy uploads your packaged Maven module to another (usually remote) repository, to be accessed by other, not necessarily local, Maven builds.


1 Answers

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)

like image 194
Eugene Evdokimov Avatar answered Nov 03 '22 00:11

Eugene Evdokimov