Recently I tried using JDK-7 for one small Java project with Maven and I faced issues in surefire plugin:
[bash]
[INFO] Surefire report directory: /Users/shrikant/code/eclipse-to-maven/target/surefire-reports
org.apache.maven.surefire.booter.SurefireExecutionException: com/shri/eclipsetomaven/ClasspathToPomConverterTest : Unsupported major.minor version 51.0; nested exception is java.lang.UnsupportedClassVersionError: com/shri/eclipsetomaven/ClasspathToPomConverterTest : Unsupported major.minor version 51.0
java.lang.UnsupportedClassVersionError: com/shri/eclipsetomaven/ClasspathToPomConverterTest : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
[/bash]
Just to make sure I used following maven-compiler-plugin configuration for JDK-7 in my pom.xml. However my build still failed.
[xml]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<executable>${env.JAVA_HOME_7}/bin/javac</executable>
<fork>true</fork>
</configuration>
</plugin>
[/xml]
Surefire plugin doesn’t seem to use this configuration for compiling test cases. By default it uses the default JDK used to run the build. In my case it was JDK-6. To make it run on new JDK, I made following changes and eventually it worked.
[xml]
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<jvm>${env.JAVA_HOME_7}/bin/java</jvm>
</configuration>
</plugin>
[/xml]
Philippe Haution says
Hi,
Many thanks for your advice. I had precisely the same issue today and I solved it immediately with this quick tip.
Cheers,
Philippe
J2er says
i’m realy thankful for your help, your sour solution worked for me either.
Jarek S says
Hi !
Thank you very much for this tip. It helped me a lot with plugin !
Cheers!