According to the Maven release history, it should be possible to run any recent version of Maven (at the time of writing anyway) on JDK 7. However, when I try to do so on my Ubuntu 21.04 machine, I get an error: java.lang.UnsupportedClassVersionError: com/google/inject/Module : Unsupported major.minor version 52.0
.
It happens even while running mvn
without any parameters in a directory that doesn't contain any Java files or pom.xml
file.
Maven info:
└─❯ mvn -version
Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 1.7.0_80, vendor: Oracle Corporation, runtime: /home/jqno/.jabba/jdk/1.7.80-oracle/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.11.0-16-generic", arch: "amd64", family: "unix"
(I also have a Zulu 1.7.292 and an OpenJDK installed; the behavior there is the same.)
Full stack trace:
└─❯ mvn clean
---------------------------------------------------
constituent[0]: file:/usr/share/maven/conf/logging/
constituent[1]: file:/usr/share/maven/lib/commons-lang3.jar
constituent[2]: file:/usr/share/maven/lib/sisu-plexus.jar
constituent[3]: file:/usr/share/maven/lib/maven-core-3.x.jar
constituent[4]: file:/usr/share/maven/lib/maven-shared-utils.jar
constituent[5]: file:/usr/share/maven/lib/sisu-inject.jar
constituent[6]: file:/usr/share/maven/lib/jansi.jar
constituent[7]: file:/usr/share/maven/lib/plexus-component-annotations.jar
constituent[8]: file:/usr/share/maven/lib/plexus-interpolation.jar
constituent[9]: file:/usr/share/maven/lib/maven-settings-builder-3.x.jar
constituent[10]: file:/usr/share/maven/lib/aopalliance.jar
constituent[11]: file:/usr/share/maven/lib/wagon-provider-api.jar
constituent[12]: file:/usr/share/maven/lib/jsr250-api.jar
constituent[13]: file:/usr/share/maven/lib/slf4j-api.jar
constituent[14]: file:/usr/share/maven/lib/plexus-cipher.jar
constituent[15]: file:/usr/share/maven/lib/maven-slf4j-provider-3.x.jar
constituent[16]: file:/usr/share/maven/lib/maven-resolver-transport-wagon.jar
constituent[17]: file:/usr/share/maven/lib/wagon-file.jar
constituent[18]: file:/usr/share/maven/lib/plexus-sec-dispatcher.jar
constituent[19]: file:/usr/share/maven/lib/maven-resolver-provider-3.x.jar
constituent[20]: file:/usr/share/maven/lib/jcl-over-slf4j.jar
constituent[21]: file:/usr/share/maven/lib/wagon-http-shaded.jar
constituent[22]: file:/usr/share/maven/lib/maven-compat-3.x.jar
constituent[23]: file:/usr/share/maven/lib/guice-no-aop.jar
constituent[24]: file:/usr/share/maven/lib/maven-artifact-3.x.jar
constituent[25]: file:/usr/share/maven/lib/guava.jar
constituent[26]: file:/usr/share/maven/lib/maven-resolver-connector-basic.jar
constituent[27]: file:/usr/share/maven/lib/commons-cli.jar
constituent[28]: file:/usr/share/maven/lib/maven-builder-support-3.x.jar
constituent[29]: file:/usr/share/maven/lib/maven-resolver-api.jar
constituent[30]: file:/usr/share/maven/lib/plexus-utils.jar
constituent[31]: file:/usr/share/maven/lib/maven-settings-3.x.jar
constituent[32]: file:/usr/share/maven/lib/maven-resolver-util.jar
constituent[33]: file:/usr/share/maven/lib/maven-resolver-impl.jar
constituent[34]: file:/usr/share/maven/lib/cdi-api.jar
constituent[35]: file:/usr/share/maven/lib/maven-resolver-spi.jar
constituent[36]: file:/usr/share/maven/lib/maven-embedder-3.x.jar
constituent[37]: file:/usr/share/maven/lib/maven-repository-metadata-3.x.jar
constituent[38]: file:/usr/share/maven/lib/commons-io.jar
constituent[39]: file:/usr/share/maven/lib/maven-model-builder-3.x.jar
constituent[40]: file:/usr/share/maven/lib/maven-plugin-api-3.x.jar
constituent[41]: file:/usr/share/maven/lib/maven-model-3.x.jar
constituent[42]: file:/usr/share/maven/lib/javax.inject.jar
---------------------------------------------------
Exception in thread "main" java.lang.UnsupportedClassVersionError: com/google/inject/Module : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(ClassRealm.java:425)
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:42)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at org.apache.maven.cli.MavenCli.container(MavenCli.java:636)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:282)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:193)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:282)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:225)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:406)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:347)
It looks like somewhere, Maven tries to load a class that is compiled for JDK8, given that it complains about an unsupported class version of 52.0. But I don't can't find which class, or why Maven tries to load it in the first place. Everything I can find on Google seems unrelated.
What's going on? How do I fix this?
UPDATE
I've unzipped the /usr/share/maven/lib/guice-no-aop.jar
file and run javap -verbose com.google.inject.Module
, and it indeed has version 52.0. I don't know how that file got there (I would assume it was installed by apt install maven
but I'm not sure).
mvn --version
exactly as mentioned in your post because if I do that I got:Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
? Can you please recheck that? – Sexmvn
without any parameters, not evenclean
, so I don't know where the library should come from. – Labanguice-4.2.1-no_aop.jar
andguice.license
. But the jar seems to have been built by1.8.0_151-google-v7
. However,mvn
builds any project on my machine without thatUnsupportedClassVersionError
. Who removed the version from that jar in your installation? – Draytonsudo apt install maven
. I'll try to purge and re-install and see what happens. – Laban