0

我面临 Maven 和 Java 16 的问题。

问题

当我试图用 maven 打包我的项目时mvn package,我收到了这个错误:

[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

按照这个网站带来的解决方案,我修改了符号链接:

修改前

# ll /usr/share/maven/lib | grep guice
guice.jar -> ../../java/guice.jar

修复程序的应用

# sudo ln -s --force ../../java/guice-4.2.1-no_aop.jar guice.jar

修改后

# ll /usr/share/maven/lib | grep guice
guice.jar -> ../../java/guice-4.2.1-no_aop.jar

但是,这会导致一个新的错误:

# mvn
---------------------------------------------------
constituent[0]: file:/usr/share/maven/conf/logging/
constituent[1]: file:/usr/share/maven/lib/maven-resolver-transport-wagon.jar
constituent[2]: file:/usr/share/maven/lib/maven-core-3.x.jar
constituent[3]: file:/usr/share/maven/lib/guava.jar
constituent[4]: file:/usr/share/maven/lib/maven-compat-3.x.jar
constituent[5]: file:/usr/share/maven/lib/guice.jar
constituent[6]: file:/usr/share/maven/lib/maven-repository-metadata-3.x.jar
constituent[7]: file:/usr/share/maven/lib/maven-slf4j-provider-3.x.jar
constituent[8]: file:/usr/share/maven/lib/commons-io.jar
constituent[9]: file:/usr/share/maven/lib/commons-cli.jar
constituent[10]: file:/usr/share/maven/lib/jansi.jar
constituent[11]: file:/usr/share/maven/lib/maven-settings-3.x.jar
constituent[12]: file:/usr/share/maven/lib/wagon-http-shaded.jar
constituent[13]: file:/usr/share/maven/lib/maven-model-3.x.jar
constituent[14]: file:/usr/share/maven/lib/maven-resolver-impl.jar
constituent[15]: file:/usr/share/maven/lib/wagon-file.jar
constituent[16]: file:/usr/share/maven/lib/sisu-inject.jar
constituent[17]: file:/usr/share/maven/lib/commons-lang3.jar
constituent[18]: file:/usr/share/maven/lib/plexus-interpolation.jar
constituent[19]: file:/usr/share/maven/lib/maven-model-builder-3.x.jar
constituent[20]: file:/usr/share/maven/lib/cdi-api.jar
constituent[21]: file:/usr/share/maven/lib/maven-artifact-3.x.jar
constituent[22]: file:/usr/share/maven/lib/maven-resolver-api.jar
constituent[23]: file:/usr/share/maven/lib/slf4j-api.jar
constituent[24]: file:/usr/share/maven/lib/plexus-sec-dispatcher.jar
constituent[25]: file:/usr/share/maven/lib/wagon-provider-api.jar
constituent[26]: file:/usr/share/maven/lib/maven-resolver-spi.jar
constituent[27]: file:/usr/share/maven/lib/maven-settings-builder-3.x.jar
constituent[28]: file:/usr/share/maven/lib/plexus-component-annotations.jar
constituent[29]: file:/usr/share/maven/lib/aopalliance.jar
constituent[30]: file:/usr/share/maven/lib/plexus-utils.jar
constituent[31]: file:/usr/share/maven/lib/javax.inject.jar
constituent[32]: file:/usr/share/maven/lib/maven-shared-utils.jar
constituent[33]: file:/usr/share/maven/lib/maven-resolver-provider-3.x.jar
constituent[34]: file:/usr/share/maven/lib/maven-resolver-connector-basic.jar
constituent[35]: file:/usr/share/maven/lib/maven-resolver-util.jar
constituent[36]: file:/usr/share/maven/lib/maven-embedder-3.x.jar
constituent[37]: file:/usr/share/maven/lib/maven-builder-support-3.x.jar
constituent[38]: file:/usr/share/maven/lib/jsr250-api.jar
constituent[39]: file:/usr/share/maven/lib/maven-plugin-api-3.x.jar
constituent[40]: file:/usr/share/maven/lib/jcl-over-slf4j.jar
constituent[41]: file:/usr/share/maven/lib/plexus-cipher.jar
constituent[42]: file:/usr/share/maven/lib/sisu-plexus.jar
---------------------------------------------------
Exception in thread "main" java.lang.NoSuchMethodError: 'void com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object)'
    at com.google.inject.Key.ensureRetainedAtRuntime(Key.java:341)
    at com.google.inject.Key.strategyFor(Key.java:335)
    at com.google.inject.Key.get(Key.java:219)
    at org.eclipse.sisu.wire.ParameterKeys.<clinit>(ParameterKeys.java:28)
    at org.eclipse.sisu.wire.DependencyAnalyzer.<init>(DependencyAnalyzer.java:93)
    at org.eclipse.sisu.wire.ElementAnalyzer.<init>(ElementAnalyzer.java:104)
    at org.eclipse.sisu.wire.WireModule.configure(WireModule.java:74)
    at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:344)
    at com.google.inject.spi.Elements.getElements(Elements.java:103)
    at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:137)
    at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:103)
    at com.google.inject.Guice.createInjector(Guice.java:87)
    at com.google.inject.Guice.createInjector(Guice.java:69)
    at com.google.inject.Guice.createInjector(Guice.java:59)
    at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:481)
    at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:206)
    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 java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    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)

这里的关键字是NoSuchMethodError关于com.google.common.base.Preconditions.checkArgument(boolean, java.lang.String, java.lang.Object)函数的,这似乎是缺失的。

从@Menghe提出并回答的这个问题中,我尝试重新安装maven,但它没有解决问题。

我的配置

软件 版本
Ubuntu 20.04.1
爪哇 16.0.2
马文 3.6.3

有没有可能得到一个建议?

在此先感谢您的帮助。

4

1 回答 1

2

删除您的发行版的 Maven 安装并从此处下载: https ://maven.apache.org/download.cgi 并进行安装。问题是基于发行版(ubuntu 或其他)中不断变化的版本,这些版本重新打包了导致问题的东西。

错误输出中的所有文件或多或少都没有完整版本号,例如原始包 maven-embedder-3.6.1.jar 中的 (maven-embedder-3.x.jar)。

我想你不会mvn --version像这样得到相同的输出:

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /Users/khmarbaise/tools/maven
Java version: 11.0.11, vendor: AdoptOpenJDK, runtime: /Users/khmarbaise/.sdkman/candidates/java/11.0.11.hs-adpt
Default locale: en_GB, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.6", arch: "x86_64", family: "mac"

特别是你不会得到括号中的哈希(cecedd343002696d0abb50b32b541b8a6ba2883f)

于 2021-07-30T15:18:05.637 回答