Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven enforcer doesn't detect jdk 1.7

Tags:

java

maven

I am using maven enforcer plugin to enforce only jdk 1.7 (I am using java.nio.file). For some reason, maven enforcer plugin can't detect jdk 1.7.

λ ~/ java -version
java version "1.7.0_13"
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)
λ ~/ javac -version
javac 1.7.0_13
λ ~/ mvn --version
Apache Maven 3.0.5 (r01de14724cdef164cd33c7c8c2fe155faf9602da; 2013-02-19 15:51:28+0200)
Maven home: /usr/local/Cellar/maven/3.0.5/libexec
Java version: 1.7.0_13, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_13.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.7.5", arch: "x86_64", family: "mac"

This is the code I have in my pom.xml -

   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-enforcer-plugin</artifactId>
      <executions>
        <execution>
          <id>enforce-versions</id>
          <goals>
            <goal>enforce</goal>
          </goals>
          <configuration>
            <rules>
              <requireJavaVersion>
                <version>1.7</version>
              </requireJavaVersion>
            </rules>
          </configuration>
        </execution>
      </executions>
    </plugin>

And this is the error I get -

[INFO] --- maven-enforcer-plugin:1.2:enforce (enforce-versions) @ com.microsoft.gittf.core ---
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireJavaVersion failed with message:
Detected JDK Version: 1.6.0-43 is not in the allowed range 1.7.

EDIT

mvn enforcer:display-info

shows version 1.7 and not 1.6... why the enforce detects java version 1.6?

like image 982
Yosi Avatar asked Mar 29 '13 21:03

Yosi


1 Answers

The version decleration is fixed. What you gave is a exact version of java. Always remember if we are not sure about exact version we should use give the range. Change the version to [1.7,)

          <requireJavaVersion>
            <version>[1.7,)</version>
          </requireJavaVersion>

This means any version equal or greater than 1.7 is acceptable.

like image 78
Vikram Palakurthi Avatar answered Sep 20 '22 23:09

Vikram Palakurthi