我可以在没有 pom.xml 的情况下从本地存储库中删除 jar 吗?

Can I remove jar from local repository without pom.xml?

我通过命令将我的 jar 安装到本地存储库:

mvn install:install-file -Dfile=aaa.jar -DgroupId=bbb -DartifactId=ccc -Dversion=1.0 -Dpackaging=jar

现在我想将其从存储库中删除。我尝试命令:

mvn dependency:purge-local-repository -DmanualInclude=bbb-ccc

但是报错:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.8:purge-local-repository (default-cli): Goal requires a project to execute but there is no POM in this directory (...). Please verify you invoked Maven from the correct directory. -> [Help 1]

然后我用数据创建pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <groupId>bbb</groupId>
  <artifactId>ccc</artifactId>
  <version>1.0</version>
  <modelVersion>4.0.0</modelVersion>
  <packaging>jar</packaging>

  <properties> 
    <groupId>${project.groupId}</groupId>
    <artifactId>${project.artifactId}</artifactId>
    <version>${project.version}</version>
    <packaging>${project.packaging}</packaging>
    <file>aaa.jar</file>
  </properties>     
</project> 

现在我可以从存储库中删除 jar。但是我可以在不创建 pom.xml 的情况下通过命令行删除吗?

我正在使用 3.2.5 (windows x64)。

dependency:purge-local-repository目标,目前版本2.10,需要在Maven项目上执行:

Requires a Maven project to be executed.

这个目标的目的之一是从本地仓库中移除一个Maven项目的依赖,所以它需要一个来执行。这解释了您遇到的错误。

然而,使用这个插件,可以指定一个 manualInclude 参数,这将删除指定为 groupId:artifactId:version 的任何依赖项或 groupId:artifactId 的所有版本,甚至是groupId。因此,插件可以更新为不需要执行 Maven 项目。

我继续,创建了 JIRA 问题 MDEP-537 来跟踪此添加并将在版本 3.0.0 中修复此问题。

正如 Tunaki 在他的回答中提到的,他请求 MDEP-537 使依赖插件能够在没有 Maven 项目的情况下清除。这已从版本 3.0.0.

开始实施

如果您只 运行 mvn dependency:purge-local-repository,您很可能 运行 旧版本 。例如我的 Maven 3.6.0 带有依赖插件版本 2.8.0.

所以你应该运行一个特定版本的插件:

mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:purge-local-repository -DmanualInclude=...