Java 无法执行目标 org.apache.maven.plugins:maven-enforcer-plugin

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45337558/
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-12 01:59:46  来源:igfitidea点击:

Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin

javaspringmavennetbeans

提问by Hsneider Salgado Neid

I got a maven spring project but when I try to run it, I can't... some idea about it...
The next is the Error Message:

我有一个 maven spring 项目,但是当我尝试运行它时,我不能......关于它的一些想法......
接下来是错误消息:

BUILD FAILURE
------------------------------------------------------------------------
Total time: 4.532s
Finished at: Wed Jul 26 16:04:06 COT 2017
Final Memory: 17M/196M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4.1:enforce
(enforce-versions) on project SIMI: Some Enforcer rules have failed. Look above for
specific messages explaining why the rule failed. -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.

Re-run Maven using the -X switch to enable full debug logging.

使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。

For more information about the errors and possible solutions, please read the following articles: [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

有关错误和可能的解决方案的更多信息,请阅读以下文章: [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

回答by Mayank Sharma

If you are using version 1.4.1of maven-enforcer-pluginand it is resulting in this error then you need to use an older version of maven-enforcer-plugin. You can find the Maven dependency below :

如果您使用的版本1.4.1maven-enforcer-plugin,它是造成这种错误,那么你需要使用的旧版本 maven-enforcer-plugin。您可以在下面找到 Maven 依赖项:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
</plugin>

Other versions can be found from the link below.

其他版本可以从下面的链接找到。

https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-enforcer-plugin

https://mvnrepository.com/artifact/org.apache.maven.plugins/maven-enforcer-plugin

Also, check your Maven version. If you are using maven 3.0.xthen you need to use maven-enforcer-plugin 1.4.1.

另外,请检查您的 Maven 版本。如果您正在使用,maven 3.0.x那么您需要使用maven-enforcer-plugin 1.4.1.

回答by arash nadali

one thing that may cause this problem is that in your project in a POM file required java or maven version is set. you should find it... but how ? maybe you couldn't find any enforcer in your project like me ... (I had the same problem and I became confused because enforcer plugin was not defined in my projects POMs, so I couldn't find it).

可能导致此问题的一件事是在您的项目中的 POM 文件中设置了所需的 java 或 maven 版本。你应该找到它……但是怎么找到?也许你在你的项目中找不到像我一样的执行器......(我遇到了同样的问题,我变得很困惑,因为我的项目 POM 中没有定义执行器插件,所以我找不到它)。

enforcer plugin is in your "effective pom"and you should check it. Effective pomis a configuration file made from super pom + project pom. maven use this configuration file to execute the relevant goal. It helps developers to specify minimum configuration detail in his/her pom.xml. Although configurations can be overridden easily.

执行器插件在您的“有效 pom”中,您应该检查它。 有效的 pom是由超级 pom + 项目 pom 组成的配置文件。maven 使用这个配置文件来执行相关目标。它帮助开发人员在他/她的 pom.xml 中指定最低配置细节。尽管可以轻松覆盖配置。

For showing your effective pom there are 2 ways: 1- use maven command, run this command :

为了显示您的有效 pom,有两种方法: 1- 使用 maven 命令,运行以下命令:

 mvn help:effective-pom

2- use your IDE : in Maven window right click on your project node and select show effective POM(it depends on your IDE).

2-使用您的IDE:在Maven窗口中右键单击您的项目节点并选择显示有效的POM(这取决于您的IDE)。

after you find what your forces are you can find it in your project and change it. for me, My effective POMhad enforcer plugin which its requireMavenVersion rule for using Java was 1.8. so I changed my project JDK version to 1.8 and luckily the problem was solved.

在你找到你的力量之后,你可以在你的项目中找到它并改变它。对我来说,我的有效 POM有执行器插件,它使用 Java 的 requireMavenVersion 规则是 1.8。所以我将我的项目 JDK 版本更改为 1.8,幸运的是问题解决了。

I hope this answer could help you.

我希望这个答案可以帮助你。

回答by Miryam Chaabouni

It is possible that someone is enforcing a specific Maven version.

有人可能正在强制执行特定的 Maven 版本。

If you see the following message:

如果您看到以下消息:

[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireMavenVersion failed with message: Detected Maven Version: 3.5.4 is not in the allowed range [3.5.2,3.5.2].

[警告] 规则 0:org.apache.maven.plugins.enforcer.RequireMavenVersion 失败并显示消息:检测到的 Maven 版本:3.5.4 不在允许范围内 [3.5.2,3.5.2]。

Then change your maven installation to the something in the specified range. In this example, only version 3.5.2 is allowed.

然后将您的 maven 安装更改为指定范围内的内容。在此示例中,仅允许版本 3.5.2。

回答by jAvA

I faced the same issue and resolved it by fixing the pom versions. Below command didn't run properly on all the sub pom's which resulted in different pom versions. 'mvn versions:set -DnewVersion=${NEW_VERSION} versions:commit' Check whether all the moms have same version if there is dependent pom's.

我遇到了同样的问题并通过修复 pom 版本解决了它。下面的命令没有在所有子 pom 上正确运行,导致不同的 pom 版本。'mvn versions:set -DnewVersion=${NEW_VERSION} versions:commit' 如果有依赖的pom,检查所有妈妈是否有相同的版本。

回答by Leonis

I had this problem because Java (java) was version 8 and the Java compiler (javac) was version 11.

我遇到这个问题是因为 Java (java) 是版本 8,而 Java 编译器 (javac) 是版本 11。

This is typical for Windows users, if you need to switch between versions manually.

如果您需要手动在版本之间切换,这对于 Windows 用户来说是典型的。

Please check the versions first:

请先检查版本:

java -version
javac -version

If an IDE is used, for example an IntelliJ Idea, then I will advise to carefully study the project settings as well. Perhaps it makes sense to completely delete the files generated by the IDE and import the project again.

如果使用 IDE,例如 IntelliJ Idea,那么我建议您也仔细研究项目设置。也许完全删除IDE生成的文件并重新导入项目是有意义的。

回答by Ramesh Hawking

After doing some research found an answer for this .if your using IntelliJ

在做了一些研究之后找到了答案。如果您使用 IntelliJ

Go to Settings ---> builds --> Maven -->set the Maven home directory.

Go to Settings ---> builds --> Maven -->set the Maven home directory.

enter image description here

在此处输入图片说明