JDK7, mvn-3.2.2 - maven-enforcer-plugin - RequireJavaVersion failed

java-7, maven, maven-3, pom.xml

Solution

If you want to include version 1.7.0-30 in the accepted range, then you have to use square brackets when you declare the range. And you can leave out version 1.6 as it is included in the range:

<requireJavaVersion>
    <version>[1.5,1.7.0-60]</version>
</requireJavaVersion>

Problem

I'm using `JDK 1.7.0_60` and `maven-3.2.2`. When I run `mvn clean install` on my project `new-project`, I get the following error- ``` [INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ new-project --- [INFO] [INFO] --- maven-enforcer-plugin:1.3.1:enforce (default) @ new-project --- [WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message: Detected JDK Version: 1.7.0-60 is not in the allowed range [1.5,1.6,1.7.0-60). [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.621 s [INFO] Finished at: 2014-07-10T20:37:32+05:30 [INFO] Final Memory: 7M/18M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.3.1:enforce (default) on project new-project: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException ``` Here are parts of my `pom.xml` as I cannot share the complete content- ``` <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <showDeprecation>true</showDeprecation> <source>1.7.0-60</source> <target>1.7.0-60</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-eclipse-plugin</artifactId> <configuration> <classpathContainers> <classpathContainer> org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5 </classpathContainer> </classpathContainers> <additionalConfig> <file> <name> .settings/org.eclipse.core.resources.prefs </name> <content> eclipse.preferences.version=1${line.separator}encoding/&lt;project&gt;=UTF-8${line.separator} </content> </file> </additionalConfig> <downloadSources>true</downloadSources> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <configuration> <rules> <requireJavaVersion> <version>[1.5,1.6,1.7.0-60)</version> </requireJavaVersion> <requireMavenVersion> <version>[3.2.2,)</version> </requireMavenVersion> </rules> </configuration> <executions> <execution> <goals> <goal>enforce</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-javadoc-plugin</artifactId> <configuration> <sourcepath> ${project.basedir}/src/main/javadoc;${project.basedir}/src/main/java </sourcepath> <charset>UTF-8</charset> <docencoding>UTF-8</docencoding> <docfilessubdirs>true</docfilessubdirs> <links> <link> http://docs.oracle.com/javase/7/docs/api/ </link> </links> <source>1.7.0-60</source> <show>protected</show> </configuration> <reportSets> <reportSet> <reports> <report>javadoc</report> </reports> </reportSet> </reportSets> </plugin> ```

Original source