17
votes

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

13
Can you post the complete stacktrace? It says "look above for specfiic messages". Also can you post the parent's pom.xml as well? I believe that contains the actual enforcer plugin as this pom doesn't have it.yaswanth
It's hard to help without the upper part of the stacktrace to see which enforcer rule failed.Mig82

13 Answers

20
votes

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

enforcer plugin is in your "effective pom" and you should check it. Effective pom is 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.

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

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

after you find what your forces are you can find it in your project and change it. for me, My effective POM had 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.

I hope this answer could help you.

5
votes

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.

4
votes

If you are using version 1.4.1 of maven-enforcer-plugin and 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 :

<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

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

4
votes

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.

1
votes

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.

1
votes

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.

0
votes

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.

0
votes

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

0
votes

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.

0
votes

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

0
votes

This worked for me.

mvn clean
mvn clean install
0
votes

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.

0
votes

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.