You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Maven 3.6.3与Java 16.0.2兼容异常求助:NoSuchMethodError及Guice替换后问题

Fixing Maven + Java 16 Compatibility Errors (Guice/Guava Issues)

Let's tackle this problem step by step—this is a classic compatibility issue between older Maven versions, Guice/Guava dependencies, and Java 16. Here are two reliable solutions to fix it:

Solution 1: Upgrade Maven to a Java 16-Compatible Version

Maven 3.6.3 is relatively old and lacks full support for Java 16. Upgrading to Maven 3.8.6 or later (the latest stable release as of now is 3.9.x) will automatically resolve the underlying dependency conflicts.

Follow these steps for Ubuntu 20.04:

  • Download a compatible Maven binary (we'll use 3.8.6 as an example):
    wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
    
  • Extract the archive to /usr/local:
    sudo tar xf apache-maven-3.8.6-bin.tar.gz -C /usr/local
    
  • Create a symbolic link for easy access:
    sudo ln -s /usr/local/apache-maven-3.8.6 /usr/local/maven
    
  • Update your environment variables to use the new Maven. Edit your ~/.bashrc file:
    nano ~/.bashrc
    
    Add these lines at the end:
    export MAVEN_HOME=/usr/local/maven
    export PATH=$MAVEN_HOME/bin:$PATH
    
  • Apply the changes immediately:
    source ~/.bashrc
    
  • Verify the installation:
    mvn -v
    
    You should see Maven 3.8.6+ paired with Java 16.0.2. Now try running mvn package again—the error should be resolved.

Solution 2: Replace Incompatible Guice/Guava Dependencies (Keep Maven 3.6.3)

If you can't upgrade Maven right now, you need to replace the outdated Guice and Guava jars in your system Maven's lib directory with versions compatible with Java 16.

Here's how:

  • First, backup the old jars to avoid losing them:
    sudo mv /usr/share/maven/lib/guice.jar /usr/share/maven/lib/guice.jar.bak
    sudo mv /usr/share/maven/lib/guava.jar /usr/share/maven/lib/guava.jar.bak
    
  • Download compatible versions:
    # Download Guice 4.2.3 (no_aop variant, avoids Java 16 module system conflicts)
    sudo wget -O /usr/share/maven/lib/guice.jar https://repo1.maven.org/maven2/com/google/inject/guice/4.2.3/guice-4.2.3-no_aop.jar
    # Download Guava 30.1.1-jre (contains the missing checkArgument method overload)
    sudo wget -O /usr/share/maven/lib/guava.jar https://repo1.maven.org/maven2/com/google/guava/guava/30.1.1-jre/guava-30.1.1-jre.jar
    
  • Now test running mvn package—this should fix both the initial Guice cache error and the subsequent NoSuchMethodError.

Why This Works

  • The original Could not initialize class com.google.inject.internal.cglib.core.$MethodWrapper error happens because older Guice versions use CGLIB, which has compatibility issues with Java 16's module system. The no_aop Guice variant skips this problematic dependency.
  • The NoSuchMethodError occurs because your system's Guava version is too old—Guava 30.1.1-jre includes the exact overload of Preconditions.checkArgument that Maven's dependencies rely on.

内容的提问来源于stack exchange,提问作者Gael Marcadet

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 23:07:36