Skip to content
Advertisement

Can’t run Maven 3.6.3 on JDK7

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:

JavaScript

(I also have a Zulu 1.7.292 and an OpenJDK installed; the behavior there is the same.)

Full stack trace:

JavaScript

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

Advertisement

Answer

The problem here is that Ubuntu has repackaged Maven which in result produces the issue.

As shown here if you check the version via:

JavaScript

This shows that you are NOT using Apache Maven.

If you do that on plain command line and install Apache Maven via https://maven.apache.org/download.cgi you will get an output like this:

JavaScript

The most important part is the first line:

JavaScript

This is Apache Maven.

Second if you take careful look into the error output:

JavaScript

Than you can see things like this:

JavaScript

If you take a look into an original Apache Maven lib directory the files look like this:

JavaScript

All files which are like maven-core.. etc. are containing the version number of Maven (3.6.3) also the problematic

JavaScript

You see that this is in particular different to the given output you have where only file:/usr/share/maven/lib/guice-4.2.1-no_aop.jar apart from the missing version number of the other artifacts.

That means the problem is based on the usage of Ubuntu Maven and NOT using Apache Maven which is compatible with JDK 7 where as the repackaged version of Ubuntu is simply not.

The simplest solution is to remove the ubuntu Package of Maven and install the original Apache Maven https://maven.apache.org/download.cgi then the build with JDK 7 will work. (Download and check the checksums etc.)

Also you can download the Apache Maven and check the checksums of files against the ones of your distro (/usr/share/maven/lib/) I bet that all files are different.

The issue is based on the idea of distros to repackage Application (for example Maven) with their dependencies which are on their system which in reality means you have different versions of dependencies which results in such issues.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement