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

Viewed 108097

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:

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.

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

14 Answers

You should solve the root cause of the issue, conflict between some of your dependecies, mvn/java version, there is a lot of possible reasons.

You might run mvn dependency:tree and check in the list if there is maybe 2 different versions or implementations of the same library from different package. Often you will have a parent pom or a dependency somewhere in the framework uncompatible with one that you added into your pom.

But often, despite this enforcer error your project could build and run perfectly so this is a workaround to build ignoring the error

To skip enforcer (not always working)

mvn clean install -Denforcer.skip=true

To continue the build if error

mvn clean install -Denforcer.fail=false

There is probably some ways to exclude a specific library from the enforcer rules too which is probably better that juste skipping everything.

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

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

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

This error is likely caused due to a mismatch of the java version specified in the pom file and the java in your system. I had Java 16 installed in my system but the pom pointed to java version 8.

There are 2 ways to solve this:

  1. Update the java version in the pom file to the java version installed on your PC, but this will likely cause a lot of dependency issues.
  2. Uninstall java installed in your system, and reinstall the java version specified in the pom file. You can do this by following the steps mentioned below:

Check the java version in your system with the following command:

java -version

And then check the java version defined in your pom file. It'd be something like

<project.java.version>1.8</project.java.version>

Install JDK 8.

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

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

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.

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.

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

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

enter image description here

I faced this issue. Its because of the maven binary version used.

I have used maven 3.0.3 version. and the enforcer plugin wasn't reliable with that. So changed the maven binary to latest 3.6.3. And the issue got resolved and working awesome.

Firslty go tto project and run mvn clean , if build is success then just check whether the required dependency is downloaded in your .m2 folder or not , If dependency does not get downloaded in your local .m2 folder , it means either version number is incorrect for that dependency or artifactory path is not correct

Else if mvn clean itself fails while dependency exist in your .m2 folder , means yoru settings.xml file actually got corrupted

You should probably check if you have two different versions of same artifact somewhere. I faced it when I wanted to add new maven dependency while I already added it on a different dependent project with different versions.

Check your maven version, for example, if you are installing Apache-CXF 3.6 and your maven version is 3.0.5, then you get errors. If you're installing Apache-CXF 3.6, the minimun version of maven must be 3.1, and the minimun version of Java must be 8.

In my case, apparently there was a configuration conflict that generated this error. So when I temporarily deleted the /home/myuser/.m2/settings.xml file, the per-line maven execution was successful.

Note: In my scenario, I had Eclipse with the maven plugin and I was trying to use maven by command line and then this error message appeared.

This worked for me.

mvn clean
mvn clean install
Related