Java 当我在命令提示符下编写 mvn help:effective-pom 时,为什么会出现错误“在当前项目中找不到前缀‘help’的插件”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26364608/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:22:30  来源:igfitidea点击:

why is there the error "No plugin found for prefix 'help' in the current project" when I write mvn help:effective-pom in the command prompt?

javamavenpom.xml

提问by

I'm reading a tutorial about maven and it should be mentioned that I know nothing about it. I have done first and second chapter successfully which was about it's setup. but in chapter 3 which is "Maven Pom" I have a problem. In last paragraph it says to make a "pom.xml" file in any directory you wish and write this in it:

我正在阅读有关 maven 的教程,应该提到的是我对此一无所知。我已经成功完成了关于它的设置的第一章和第二章。但是在“Maven Pom”的第 3 章中,我遇到了问题。在最后一段中,它说在您希望的任何目录中创建一个“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>

and then it says that an easy way to look at the default configurations of the super POM is by running the following command: mvn help:effective-pomin the command prompt.

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

But when I try this, I get this error:

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

No plugin found for prefix 'help' in the current project

This is the tutorial I mentioned above: maven tutorial

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

Why there is no plugin help in my repository folder?! and how I can get it?

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

This is the output of mvn --version in the cmd:

这是 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"

This is the rezult of mvn -X help:effective-pom(first ten lines)

这是 mvn -X help: Effective-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

回答by Aaron Digulla

The command should work. If it doesn't, then that means you made a mistake in the setup of Maven or it printed more errors before that, namely that it could download plugins from Maven Central.

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

Delete the folder %HOME%/.m2/repository/and try again. Now look closely for any problems in the output of Maven.

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

If it still doesn't work, show us the content of %HOME%/.m2/repository/org/apache/maven/plugins/maven-help-plugin/

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

回答by DB5

Background Information

背景资料

When you execute mvn help:effecitve-pom, helpis a prefix which represents a specific plugin while effective-pomis the goal from that plugin that should be executed.

当您执行mvn help:effecitve-pom,help是代表特定插件的前缀,而是effective-pom该插件应该执行的目标。

The first thing Maven does is try to lookup the full plugin based on the given prefix (so in your case the prefix help). Normally it does this by checking the /org/apache/maven/plugins/maven-metadata.xmlfile in your local repository (by default your local repository is stored under %HOME%/.m2/repository).

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

If this file doesn't exist then it tries to check it remotely (again default configuration would use maven central), and will then cache this file in your local repository with the following name: maven-metadata-<remote-repo-id>.xml(so for maven central it would be: maven-metadata-central.xml). If at this point it is unable to access this file remotely then it wont be able to find the plugin and will fail the build. This is exactly what you are experiencing.

如果此文件不存在,则它会尝试远程检查它(同样,默认配置将使用 maven central),然后将使用以下名称将此文件缓存在本地存储库中:(maven-metadata-<remote-repo-id>.xml因此对于 maven central,它将是:)maven-metadata-central.xml。如果此时它无法远程访问此文件,则它将无法找到该插件并且构建失败。这正是你正在经历的。

Your Issue

你的问题

There are two main reasons why it wont be able to resolve the plugin:

无法解析插件的主要原因有两个:

  • the local files in your repository are corrupt in some way
  • maven is unable to access the remote repository (so basically a problem with your internet connection).
  • 存储库中的本地文件以某种方式损坏
  • maven 无法访问远程存储库(因此基本上是您的 Internet 连接问题)。

You can use the debug flag -Xwhen executing your maven build to receive more information about what is going on. For you executing the following:

您可以-X在执行 Maven 构建时使用调试标志来接收有关正在发生的事情的更多信息。为您执行以下操作:

mvn -X help:effective-pom

should provide information about how it is trying to resolve the plugin prefix. For example if I execute this command I see the following:

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

[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.

My locally cached file from the remote repository is up to date so it will just use that.

我来自远程存储库的本地缓存文件是最新的,因此它只会使用它。

Do either /org/apache/maven/plugins/maven-metadata.xmlor /org/apache/maven/plugins/maven-metadata-central.xmlexist in your local repository? If they don't then most likely you have an internet connection problem. If they do exist then they might be corrupt. What is the result of running with the -Xflag, what information does it provide?

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

After all this usually the simplest solution is to delete your local repository (by default %HOME%/.m2/repository, but running maven with the -Xflag will tell you exactly where it is), and execute maven again. By deleting the local repository you force maven to download everything again.

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

回答by Lionel Orellana

If you are using a mirror of central you might need to define the prefix in the plugin metadata file for your mirror.

如果您使用的是中央镜像,则可能需要在镜像的插件元数据文件中定义前缀。

The file

文件

.m2/repository/org/apache/maven/plugins/maven-metadata-<mirror id>.xml

.m2/repository/org/apache/maven/plugins/maven-metadata-<mirror id>.xml

must contain

必须包含

<plugin>
   <name>Maven Help Plugin</name>
   <prefix>help</prefix>
   <artifactId>maven-help-plugin</artifactId>
</plugin>

回答by Andreas Panagiotidis

Like in a similar topic in stackoverflow, just use a plugin directly in the pom, for example:

就像在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>