当我在命令提示符下写mvn help:effective-pom时,为什么会出现错误"当前项目中找不到前缀'帮助'的插件"?

4 java pom.xml maven

我正在阅读关于maven的教程,应该提到我对此一无所知.我已经成功完成了第一章和第二章,这是关于它的设置.但在第3章"Maven Pom"中我遇到了问题.在上一段中,它表示要在您希望的任何目录中创建一个"pom.xml"文件并在其中写入:

 <project xmlns="http://maven.apache.org/POM/4.0.0"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
   http://maven.apache.org/xsd/maven-4.0.0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <groupId>com.companyname.project-group</groupId>
   <artifactId>project</artifactId>
   <version>1.0</version>

</project>
Run Code Online (Sandbox Code Playgroud)

然后它说一个简单的方法来查看超级POM的默认配置是通过运行以下命令:mvn help:effective-pom在命令提示符下.

但是当我尝试这个时,我得到了这个错误:

No plugin found for prefix 'help' in the current project
Run Code Online (Sandbox Code Playgroud)

这是我上面提到的教程:maven教程

为什么我的存储库文件夹中没有插件帮助?!我怎么能得到它?

这是cmd中mvn --version的输出:

Apache Maven 3.2.3
Maven home: C:\apache-maven-3.2.3
Java version: 1.6.0_13
Java home: C:\Program Files\Java\jdk1.6.0_13
Default locale: en_US, platform encoding: Cp1252
OS name: "windows Vista",version:"6.8"
Run Code Online (Sandbox Code Playgroud)

这是mvn -X帮助的结果:有效pom(前十行)

[INFO] Scanning for projects...
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.4/maven-install-plugin-2.4.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.4: Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.4
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-resources-plugin:2.6: Plugin org.apache.maven.plugins:maven-resources-plugin:2.6 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-resources-plugin:jar:2.6
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-surefire-plugin/2.12.4/maven-surefire-plugin-2.12.4.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-surefire-plugin:2.12.4: Plugin org.apache.maven.plugins:maven-surefire-plugin:2.12.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-surefire-plugin:jar:2.12.4
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-compiler-plugin/3.1/maven-compiler-plugin-3.1.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-compiler-plugin:3.1: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-jar-plugin/2.4/maven-jar-plugin-2.4.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-jar-plugin:2.4: Plugin org.apache.maven.plugins:maven-jar-plugin:2.4 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-jar-plugin:jar:2.4
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom

[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.3/maven-site-plugin-3.3.pom
Run Code Online (Sandbox Code Playgroud)

DB5*_*DB5 6

背景资料

执行时mvn help:effecitve-pom,help是一个代表特定插件的前缀,而effective-pom该插件的目标是应该执行的.

Maven做的第一件事是尝试根据给定的前缀查找完整的插件(所以在你的情况下是前缀help).通常,它通过检查/org/apache/maven/plugins/maven-metadata.xml本地存储库中的文件来执行此操作(默认情况下,您的本地存储库存储在其中%HOME%/.m2/repository).

如果这个文件不存在,那么它会尝试远程查看(再次默认配置将使用Maven的中央),然后将缓存在本地资源库此文件具有以下名称:maven-metadata-<remote-repo-id>.xml(所以行家中心这将是:maven-metadata-central.xml).如果此时它无法远程访问此文件,那么它将无法找到该插件并且将无法构建.这正是您所经历的.

你的问题

有两个主要原因导致它无法解析插件:

  • 存储库中的本地文件以某种方式损坏
  • maven无法访问远程存储库(所以基本上是您的Internet连接问题).

您可以-X在执行maven构建时使用debug标志来接收有关正在进行的操作的更多信息.为执行以下操作:

mvn -X help:effective-pom
Run Code Online (Sandbox Code Playgroud)

应该提供有关它如何尝试解析插件前缀的信息.例如,如果我执行此命令,我会看到以下内容:

[DEBUG] Resolving plugin prefix help from [org.apache.maven.plugins, org.codehaus.mojo]
[DEBUG] Could not find metadata org.apache.maven.plugins/maven-metadata.xml in local (/home/user/.m2/repository)
[DEBUG] Skipped remote update check for org.apache.maven.plugins/maven-metadata.xml, locally cached metadata up-to-date.
Run Code Online (Sandbox Code Playgroud)

我在远程存储库中的本地缓存文件是最新的,因此它只会使用它.

无论是做/org/apache/maven/plugins/maven-metadata.xml还是/org/apache/maven/plugins/maven-metadata-central.xml在本地资源库是否存在?如果他们没有,那么很可能你有互联网连接问题.如果他们确实存在,那么他们可能会腐败.运行-X旗帜的结果是什么,它提供了哪些信息?

在所有这些之后,通常最简单的解决方案是删除本地存储库(默认情况下%HOME%/.m2/repository,但使用-X标志运行maven 会告诉您确切的位置),然后再次执行maven.通过删除本地存储库,您强制maven再次下载所有内容.


Aar*_*lla 0

该命令应该有效。如果没有,则意味着您在 Maven 设置中犯了一个错误,或者在此之前它打印了更多错误,即它可以从 Maven Central 下载插件。

删除该文件夹%HOME%/.m2/repository/并重试。现在仔细查看 Maven 输出中是否存在任何问题。

如果仍然不起作用,请向我们展示以下内容%HOME%/.m2/repository/org/apache/maven/plugins/maven-help-plugin/