我已经使用Maven 3.0.4
安装了Homebrew
,每当我运行mvn
命令时,我都会得到以下内容:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
从谷歌搜索错误似乎与某种 Google番石榴工具/库有关 - 我对此一无所知。 我尝试替换/bin
maven
目录中的一些Jars,但它没有任何影响
有任何帮助吗?我不知道问题在哪里开始,但现在我无法使用mvn
运行任何内容。
以下是相关问题,但我的项目并没有直接引用guava*.jar
文件:
NoSuchMethod error getting a gdata service
这是完整的mvn -X(我在当前目录中使用pom.xml运行)
Jordans-iMac:spring-mvc-setup jordanbaucke$ mvn -X
Apache Maven 3.0.4 (r1232337; 2012-01-17 01:44:56-0700)
Maven home: /usr/local/Cellar/maven/3.0.4/libexec
Java version: 1.7.0_09, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.8.2", arch: "x86_64", family: "mac"
---------------------------------------------------
constituent[0]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/aether-api-1.13.1.jar
constituent[1]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/aether-connector-wagon-1.13.1.jar
constituent[2]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/aether-impl-1.13.1.jar
constituent[3]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/aether-spi-1.13.1.jar
constituent[4]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/aether-util-1.13.1.jar
constituent[5]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/commons-cli-1.2.jar
constituent[6]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-aether-provider-3.0.4.jar
constituent[7]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-artifact-3.0.4.jar
constituent[8]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-compat-3.0.4.jar
constituent[9]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-core-3.0.4.jar
constituent[10]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-embedder-3.0.4.jar
constituent[11]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-model-3.0.4.jar
constituent[12]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-model-builder-3.0.4.jar
constituent[13]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-plugin-api-3.0.4.jar
constituent[14]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-repository-metadata-3.0.4.jar
constituent[15]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-settings-3.0.4.jar
constituent[16]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/maven-settings-builder-3.0.4.jar
constituent[17]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/plexus-cipher-1.7.jar
constituent[18]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/plexus-component-annotations-1.5.5.jar
constituent[19]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/plexus-interpolation-1.14.jar
constituent[20]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/plexus-sec-dispatcher-1.3.jar
constituent[21]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/plexus-utils-2.0.6.jar
constituent[22]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/sisu-guava-0.9.9.jar
constituent[23]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/sisu-guice-3.1.0-no_aop.jar
constituent[24]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/sisu-inject-bean-2.3.0.jar
constituent[25]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/sisu-inject-plexus-2.3.0.jar
constituent[26]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/wagon-file-2.2.jar
constituent[27]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/wagon-http-2.2-shaded.jar
constituent[28]: file:/usr/local/Cellar/maven/3.0.4/libexec/lib/wagon-provider-api-2.2.jar
---------------------------------------------------
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;
at com.google.inject.internal.InstanceBindingImpl.<init>(InstanceBindingImpl.java:51)
at com.google.inject.internal.BindingBuilder.toInstance(BindingBuilder.java:95)
at com.google.inject.internal.InjectorShell$RootModule.configure(InjectorShell.java:329)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:229)
at com.google.inject.spi.Elements.getElements(Elements.java:103)
at com.google.inject.internal.InjectorShell$Builder.build(InjectorShell.java:136)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:104)
at com.google.inject.Guice.createInjector(Guice.java:94)
at com.google.inject.Guice.createInjector(Guice.java:71)
at com.google.inject.Guice.createInjector(Guice.java:61)
at org.codehaus.plexus.DefaultPlexusContainer.addPlexusInjector(DefaultPlexusContainer.java:470)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:196)
at org.codehaus.plexus.DefaultPlexusContainer.<init>(DefaultPlexusContainer.java:160)
at org.apache.maven.cli.MavenCli.container(MavenCli.java:375)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:191)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)
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:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
更新
降级到Java 1.6,也卸载了Macports。同样的问题。
答案 0 :(得分:3)
问题是MAVEN_HOME变量的错误集导致它指向错误的文件夹
Maven home: /usr/local/Cellar/maven/3.0.4/libexec
此外,您使用的安装看起来不像maven.apache.org下载页面的默认设置。
您应该从maven.apache.org下载apache-maven-3.0.4-bin.tar.gz解压缩它并将MAVEN_HOME指向提取的存档的根目录,如:
/usr/local/apache-maven-3.0.4
并将bin文件夹/usr/local/apache-maven-3.0.4/bin放入PATH。如果你打电话
mvn --version
应该打印出类似以下内容的东西:
mac:~ km$ mvn --version
Apache Maven 3.0.4 (r1232337; 2012-01-17 09:44:56+0100)
Maven home: /usr/share/maven
Java version: 1.6.0_26, vendor: Apple Inc.
Java home: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
Default locale: en_US, platform encoding: MacRoman
OS name: "mac os x", version: "10.5.8", arch: "x86_64", family: "mac"
mac:~ km$
答案 1 :(得分:2)
看起来您安装的Maven版本依赖于不正确的Guava版本。 Maven 3显然依赖于Guice和Guava,因此错误并非完全是虚假的。这可能是您正在使用的Homebrew软件包有一个问题,它具有不正确的库依赖项(它似乎使用0.9.9的Guava。您应该使用软件包维护者和/或安装tarball / zip版本而不是使用它自制。
答案 2 :(得分:0)
使用maven 3.2.2和Java 1.8在OS X上面临类似的问题。 &#39; mvn clean test&#39;失败,没有发现类定义错误。 将maven升级到3.3.9并且能够成功运行mvn命令。
答案 3 :(得分:0)
可能是您的某些jar依赖于google / guava jar,如果它们不在构建路径中,或者如果存在多个,则可能会导致不一致,从而导致错误。 一种快速的解决方案是将最新版本的番石榴添加到您的pom中
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>24.0-jre</version>
</dependency>
现在检查依赖关系层次结构中,除番石榴之外的任何Jar是否都引用了其他任何较旧的番石榴/ google-collection jar。如果是这样,那就排除它,像这样
<exclusions>
<exclusion>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>