Java、mvn工具,如何使用mvn卸载包?有一些插件、工具、shell脚本和命令方法吗?
如果您想卸载/删除 maven 下载的任何工件,只需转到存储所有已安装工件的
~/.m2/repository
目录,然后删除您想要删除的工件。
您所要做的就是从您的
pom.xml
中删除依赖项,maven 应该处理其余的事情。
我真的很挣扎,因为我有一个上游依赖项,其中包括我试图删除的依赖项,所以即使
mvn dependency:purge-local-repository
也没有帮助 - 在这种情况下,可能值得尝试配置依赖项排除(也在 pom.xml
文件)。
我正在学习
mvn
,在入门指南中,我大约有 mvn install
。
看起来
mvn
并没有提供开箱即用的卸载程序(尽管它确实有mvn clean
,它可以做其他事情,可能是同时发明的automake clean)。
所以对我来说,选项变成了:
(A) 阅读
mvn install
做了什么:
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ my-app ---
[INFO] Installing /home/peter/Projects/my-app/target/my-app-1.0-SNAPSHOT.jar to /home/peter/.m2/repository/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.jar
[INFO] Installing /home/peter/Projects/my-app/pom.xml to /home/peter/.m2/repository/com/mycompany/app/my-app/1.0-SNAPSHOT/my-app-1.0-SNAPSHOT.pom
所以我可以手动反转它(对于 macOS/Linux,Windows 留给感兴趣的读者作为练习):
cd ~/.m2/repository
cd com
rm -rf mycompany
由于示例项目只有 JUnit 作为测试依赖项,我还不清楚如何安装或卸载非测试依赖项。
(B) 编写一个脚本来反转 (A),本着 Maven 哲学 的精神,在实践中这似乎意味着 编写一个插件...所以考虑一下在其他 Apache 项目中是如何完成的 就像
sling:uninstall
。
.m2
文件夹 是 Maven 存储依赖项的位置,因此全力以赴并删除 .m2
存储库,因为它可以通过 入门 中给出的命令重新填充,因此: rm -rf ~/.m2/repository
(D) 获取其他人的插件,看看它是否适合我(通过 this SO):
mvn build-helper:remove-project-artifact
虽然这实际上做了很多我还不明白的工作,所以让我紧张(可能的文档?),而且它实际上并没有删除现在空的
~/.m2/repository/com/mycompany/app
目录:
[WARNING]
[WARNING] Some problems were encountered while building the effective settings
[WARNING] Unrecognised tag: 'blocked' (position: START_TAG seen ...</url>\n <blocked>... @164:16) @ /usr/share/maven/conf/settings.xml, line 164, column 16
[WARNING]
[INFO] Scanning for projects...
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/maven-metadata.xml
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/maven-metadata.xml (915 B at 5.3 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/3.5.0/build-helper-maven-plugin-3.5.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/3.5.0/build-helper-maven-plugin-3.5.0.pom (7.4 kB at 255 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/mojo-parent/77/mojo-parent-77.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/mojo-parent/77/mojo-parent-77.pom (36 kB at 844 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.10.0/junit-bom-5.10.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.10.0/junit-bom-5.10.0.pom (5.6 kB at 353 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/3.5.0/build-helper-maven-plugin-3.5.0.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/mojo/build-helper-maven-plugin/3.5.0/build-helper-maven-plugin-3.5.0.jar (71 kB at 1.8 MB/s)
[INFO]
[INFO] ----------------------< com.mycompany.app:my-app >----------------------
[INFO] Building my-app 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- build-helper-maven-plugin:3.5.0:remove-project-artifact (default-cli) @ my-app ---
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/4.0.0/plexus-utils-4.0.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/4.0.0/plexus-utils-4.0.0.pom (8.7 kB at 433 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/13/plexus-13.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus/13/plexus-13.pom (27 kB at 1.4 MB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.9.3/junit-bom-5.9.3.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/junit/junit-bom/5.9.3/junit-bom-5.9.3.pom (5.6 kB at 296 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-management/3.1.0/file-management-3.1.0.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-management/3.1.0/file-management-3.1.0.pom (4.5 kB at 214 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/36/maven-shared-components-36.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/maven-shared-components/36/maven-shared-components-36.pom (4.9 kB at 233 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.pom (2.7 kB at 196 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.36/slf4j-parent-1.7.36.pom
Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-parent/1.7.36/slf4j-parent-1.7.36.pom (14 kB at 641 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/4.0.0/plexus-utils-4.0.0.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-management/3.1.0/file-management-3.1.0.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar
Downloaded from central: https://repo.maven.apache.org/maven2/org/codehaus/plexus/plexus-utils/4.0.0/plexus-utils-4.0.0.jar (192 kB at 3.5 MB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/slf4j/slf4j-api/1.7.36/slf4j-api-1.7.36.jar (41 kB at 643 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/org/apache/maven/shared/file-management/3.1.0/file-management-3.1.0.jar (36 kB at 404 kB/s)
[INFO] /home/peter/.m2/repository/com/mycompany/app/my-app removed.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.056 s
[INFO] Finished at: 2024-01-25T11:10:02+11:00
[INFO] ------------------------------------------------------------------------
(E) 暂时放弃这个,例如选择不介意混乱,我不需要空间。