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]

♀尐吖头ヾ 提交于 2019-12-05 20:22:42

问题


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.


回答1:


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)



来源:https://stackoverflow.com/questions/21341103/how-can-i-execute-the-opposite-of-mvn-install-from-a-script-that-does-not-know-t

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!