且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-11-17 23:30:28

背景信息

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

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

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

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.xml file in your local repository (by default your local repository is stored under %HOME%/.m2/repository).

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

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.

您的问题

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

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


  • 存储库中的本地文件在某种程度上已损坏

  • maven无法访问远程存储库(所以基本上是你的网络连接问题)。

你可以在执行maven构建时使用调试标志 -X 以接收有关正在进行的操作的更多信息。执行以下操作时:

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

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.

执行 /org/apache/maven/plugins/maven-metadata.xml /您的本地存储库中是否存在org / apache / maven / plugins / maven-metadata-central.xml ?如果他们没有,那么很可能你有互联网连接问题。如果他们确实存在,那么他们可能会腐败。使用 -X 标志运行的结果是什么,它提供了哪些信息?

Do either /org/apache/maven/plugins/maven-metadata.xml or /org/apache/maven/plugins/maven-metadata-central.xml exist 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 -X flag, what information does it provide?

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

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