Last Updated: February 25, 2016
·
3.368K
· helmedeiros

Maven - Unsupported major.minor version of surefire

Yesterday, I tried to set one of my maven Java projects to be deployed by travis-ci using JDK-7 and I faced issues in surefire plugin:

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)

Surefire plugin seems to use by default the default JDK used to run the build for compiling test cases. In my case it was JDK-6. To make it run on new JDK, I made following changes inside my pom.xml

<build>
    <finalName>jdk7</finalName>
    <plugins>

        <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}/bin/javac</executable>
                <fork>true</fork>
            </configuration>
        </plugin>

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