我正在阅读关于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>
然后它说一个查看超级POM默认配置的简单方法是在命令提示符下运行以下命令:mvn help:effective-pom
。
但是当我尝试这个时,我收到了这个错误:
No plugin found for prefix 'help' in the current project
这是我上面提到的教程:maven tutorial
为什么我的存储库文件夹中没有插件帮助?!以及如何获得它?
这是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"
这是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
答案 0 :(得分:5)
背景资料
当您执行mvn help:effecitve-pom
时,help
是表示特定插件的前缀,而effective-pom
是该插件应该执行的目标。
Maven做的第一件事就是尝试根据给定的前缀查找完整的插件(所以在你的例子中是前缀help
)。通常,它通过检查本地存储库中的/org/apache/maven/plugins/maven-metadata.xml
文件来执行此操作(默认情况下,您的本地存储库存储在%HOME%/.m2/repository
下)。
如果此文件不存在,则会尝试远程检查(再次默认配置将使用maven central),然后将此文件缓存在本地存储库中,名称如下:maven-metadata-<remote-repo-id>.xml
(所以对于maven中心,它将是:maven-metadata-central.xml
)。如果此时它无法远程访问此文件,那么它将无法找到该插件并且将无法构建。这正是您所经历的。
您的问题
有两个主要原因导致它无法解析插件:
执行maven构建时,您可以使用调试标志-X
来接收有关正在发生的事情的更多信息。为执行以下操作:
mvn -X help:effective-pom
应该提供有关它如何尝试解析插件前缀的信息。例如,如果我执行此命令,我会看到以下内容:
[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.
我在远程存储库中的本地缓存文件是最新的,所以它只会使用它。
本地存储库中是否存在/org/apache/maven/plugins/maven-metadata.xml
或/org/apache/maven/plugins/maven-metadata-central.xml
?如果他们没有,那么很可能你有互联网连接问题。如果他们确实存在,那么他们可能会腐败。使用-X
标志运行的结果是什么,它提供了哪些信息?
毕竟这通常最简单的解决方案是删除本地存储库(默认情况下为%HOME%/.m2/repository
,但运行带有-X
标志的maven将告诉您确切的位置),然后再次执行maven。通过删除本地存储库,您强制maven再次下载所有内容。
答案 1 :(得分:1)
该命令应该有效。如果没有,那么这意味着您在Maven的设置中犯了一个错误,或者在此之前打印了更多错误,即它可以从Maven Central下载插件。
删除文件夹%HOME%/.m2/repository/
,然后重试。现在仔细查看Maven输出中的任何问题。
如果仍然无效,请向我们展示%HOME%/.m2/repository/org/apache/maven/plugins/maven-help-plugin/
答案 2 :(得分:1)
就像在stackoverflow中的类似主题一样,只需在pom中直接使用插件,例如:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<testSource>1.8</testSource>
<testTarget>1.8</testTarget>
<compilerArgument>-Xlint:deprecation</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
答案 3 :(得分:0)
如果您使用的是中央镜像,则可能需要在镜像的插件元数据文件中定义前缀。
文件
.m2 / repository / org / apache / maven / plugins / maven-metadata-&lt; mirror id&gt; .xml
必须包含
<plugin>
<name>Maven Help Plugin</name>
<prefix>help</prefix>
<artifactId>maven-help-plugin</artifactId>
</plugin>