我正在使用JDK 1.7.0_60
和maven-3.2.2
。当我在项目mvn clean install
上运行new-project
时,出现以下错误 -
[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
以下是我pom.xml
的部分内容,因为我无法分享完整的内容 -
<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/<project>=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>
答案 0 :(得分:3)
如果要在接受的range中包含版本1.7.0-30,则在声明范围时必须使用方括号。你可以省略1.6版本,因为它包含在范围内:
<requireJavaVersion>
<version>[1.5,1.7.0-60]</version>
</requireJavaVersion>