QuickTip : Maven Surefire plugin – Unsupported major.minor version 51.0

Recently I tried using JDK-7 for one small Java project with Maven and I faced issues in surefire plugin:

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

Just to make sure I used following maven-compiler-plugin configuration for JDK-7 in my pom.xml. However my build still failed.


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

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.

<plugin>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <jvm>${env.JAVA_HOME_7}/bin/java</jvm>
  </configuration>
</plugin>

ShriKant Vashishtha is an enterprise Agile Coach, IT strategist, trainer, thinker and hands-on geek. He is passionate towards enterprise Agile transformation, quality aspect of software development including TDD, refactoring, Continuous Delivery, DevOps and Test Automation. He can be reached at vashishtha_sk@yahoo.com.

Posted in Maven, QuickTip
3 comments on “QuickTip : Maven Surefire plugin – Unsupported major.minor version 51.0
  1. 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

  2. J2er says:

    i’m realy thankful for your help, your sour solution worked for me either.

  3. Jarek S says:

    Hi !
    Thank you very much for this tip. It helped me a lot with plugin !

    Cheers!

1 Pings/Trackbacks for "QuickTip : Maven Surefire plugin – Unsupported major.minor version 51.0"
  1. […] You can edit the Java Home path or specify the JVM for maven. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

CommentLuv badge

Welcome to Sampreshan
Technology Strategist, Speaker, Scrum/XP/Agile Trainer Coach and Trainer
Your interest areas
Follow

Get every new post on this blog delivered to your Inbox.

Join other followers: