luontola / retrolambda

Backport of Java 8's lambda expressions to Java 7, 6 and 5
Apache License 2.0
3.54k stars 227 forks source link

java.lang.UnsupportedClassVersionError: Unsupported major.minor version 52.0 #142

Closed mdennis10 closed 5 years ago

mdennis10 commented 6 years ago

I have a maven project that I'm compiling using java 7. The project builds fine with anonymous inner classes, however I want to use lambda with backward compatibility. When I change my anonymous inner classes and builds the project everything works fine but when I add the maven plug-in I get the following error:

main: [exec] FATAL ERROR in native method: processing of -javaagent failed [exec] java.lang.UnsupportedClassVersionError: net/orfjackal/retrolambda/PreMain : Unsupported major.minor version 52.0 [exec] at java.lang.ClassLoader.defineClass1(Native Method) [exec] at java.lang.ClassLoader.defineClass(ClassLoader.java:800) [exec] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) [exec] at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) [exec] at java.net.URLClassLoader.access$100(URLClassLoader.java:71) [exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:361) [exec] at java.net.URLClassLoader$1.run(URLClassLoader.java:355) [exec] at java.security.AccessController.doPrivileged(Native Method) [exec] at java.net.URLClassLoader.findClass(URLClassLoader.java:354) [exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:425) [exec] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) [exec] at java.lang.ClassLoader.loadClass(ClassLoader.java:358) [exec] at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:300) [exec] at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397) [exec] Exception in thread "main"

 <build>
    <plugins>
        <plugin>
            <groupId>net.orfjackal.retrolambda</groupId>
            <artifactId>retrolambda-maven-plugin</artifactId>
            <version>2.5.4</version>
            <executions>
                <execution>
                    <goals>
                        <goal>process-main</goal>
                        <goal>process-test</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

    </plugins>
    <resources>
        <resource>
            <directory>src/main/resource</directory>
            <excludes>
                <exclude>**/*.properties</exclude>
            </excludes>
        </resource>
    </resources>
</build>
luontola commented 6 years ago

You must run Retrolambda using Java 8. The easiest way is to run Maven under Java 8, but you can also configure retrolambda-maven-plugin's java8home parameter. The tests you may run with Java 7 by setting the <jvm> parameter of maven-surefire-plugin/maven-failsafe-plugin.