15

I'm trying to build IntelliJ Project with maven on java 16.0.1, but it can't compile my project, although IntelliJ is able to do it successfuly. Before that, I used maven to compile a java 15 project, but I decided to update everything to 16.0.1 because of complete mess with different versions of java on my machine, like I was able to compile but not to run generated .jar files and etc.
mvn compile output:

[ERROR] Error executing Maven.
[ERROR] java.lang.IllegalStateException: Unable to load cache item
[ERROR] Caused by: Unable to load cache item
[ERROR] Caused by: Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper

Here is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>TaxiDB</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.0</version>
                <configuration>
                    <release>16.0.1</release>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <properties>
        <maven.compiler.source>16</maven.compiler.source>
        <maven.compiler.target>16</maven.compiler.target>
    </properties>

    <dependencies>
        ...
    </dependencies>
</project>

mvn -version output:

Apache Maven 3.6.3
Maven home: /usr/share/maven
Java version: 16.0.1, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-16-oracle
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.8.0-50-generic", arch: "amd64", family: "unix"

java -verion output:

java version "16.0.1" 2021-04-20
Java(TM) SE Runtime Environment (build 16.0.1+9-24)
Java HotSpot(TM) 64-Bit Server VM (build 16.0.1+9-24, mixed mode, sharing)
8
  • I think release should be 16, not 16.0.1 Apr 30, 2021 at 13:29
  • @JFabianMeier, tried. Same output.
    – denh
    Apr 30, 2021 at 13:31
  • Not sure if that'll help you but you didn't specify a version for the maven-jar-plugin
    – Lino
    Apr 30, 2021 at 13:58
  • @Lino, it didn't help
    – denh
    Apr 30, 2021 at 14:37
  • 2
    Upgrading to maven 3.8 solved the issue. On Ubuntu only 3.6 is available through apt so you'll have to install it manually. This is a pretty good guide: linuxize.com/post/how-to-install-apache-maven-on-ubuntu-20-04 (however, there is a mistake in the JAVA_HOME path in the script)
    – ACV
    Jun 14, 2021 at 21:58

2 Answers 2

14

The problem is your Maven version is too old. It's not compatible with JDK 16.

Try to manually install maven version 3.8.1:

https://maven.apache.org/install.html

This will solve your problem without downgrading your JDK version.

2
  • Try using sdkman to install the JDK and Maven, it will make way easier to manage your JDK and tools versions Jul 21, 2021 at 17:18
  • This solved it for me, too. Thanks!
    – Ryan
    Sep 24, 2021 at 19:18
0

I had this issue when running mvn compile on Ubuntu 20.10. Running the same maven command on Ubuntu 21.04 (the latest release) seems to be okay.

You may want to check the version of linux you are running. If running an older version, upgrade to Ubuntu 21.04.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.