4

I've installed Maven 3.0.4 with Homebrew and whenever I run the mvn command I get the following:

Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.ImmutableSet.copyOf(Ljava/util/Collection;)Lcom/google/common/collect/ImmutableSet;

From Googling the error it seems to be related some sort of Google guava tool/library -- which I know nothing about. I attempted to replaced some Jars in the /bin directory of maven but it had no affect

Any help? I don't know where the issue started but now I can't run anything with mvn.

Here is what seems to be a related question, but my project doesn't directly reference a guava*.jar file:

NoSuchMethod error getting a gdata service

Here is complete mvn -X (I am running with a pom.xml in the current directory)

    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)

Update

Downgraded to Java 1.6, uninstall Macports as well. Same problem.

Community
  • 1
  • 1
jordan.baucke
  • 4,308
  • 10
  • 54
  • 77
  • can you provide some more info? Are you just running 'mvn' or are there arguments that you are passing? Are you running it in a project directory with a pom file? Run it again with -X parameter and provide the last 10 lines or so. – kldavis4 Jan 04 '13 at 21:22
  • I'm very wary of installing Java stuff with Homebrew; I always just install the normal Java way (untar) and run it that way. – Dave Newton Jan 04 '13 at 21:23
  • @DaveNewton I reinstalled with _normal java way (untar)_ and I get the same error! – jordan.baucke Jan 04 '13 at 21:29
  • It looks like I am running 10.6.8 and khmarbase is running 10.5.8 and you are running 10.8.2, so there may be an issue with the mac jdk – kldavis4 Jan 04 '13 at 21:36
  • OSX As displayed in output: 10.8.2 – jordan.baucke Jan 04 '13 at 21:38
  • @jordan.baucke Change the value of JAVA_HOME (Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/jre) into Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home/ – khmarbaise Jan 04 '13 at 21:38
  • @kldavis4 `OS name: "mac os x", version: "10.8.2"` – Dave Newton Jan 04 '13 at 21:38
  • @khmarbaise _done_ `export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_09.jdk/Contents/Home` same issue – jordan.baucke Jan 04 '13 at 21:41
  • @jordan.baucke Have you several bin folder in your PATH variable? What does *which mvn* says ? – khmarbaise Jan 04 '13 at 21:45
  • Ok reinstall `mvn` with macports this time to keep the path updated and updated java. – jordan.baucke Jan 04 '13 at 21:59
  • Hmm, are we sure this is a problem with Homebrew? I'm running Maven installed using Homebrew and it's working just fine. Do you get the error if you run `mvn` from a folder containing no `pom.xml? as well? – Peter Svensson Jan 04 '13 at 22:00
  • @PeterLiljenberg I get it everywhere I run a `mvn` command I've uninstalled the `Homebrew` and the `tar/zip`, and am now trying to install `Mac Ports` version – jordan.baucke Jan 04 '13 at 22:06
  • What does `env|grep MAVEN_OPTS` show? – Peter Svensson Jan 04 '13 at 22:37
  • @PeterLiljenberg it doesn't return anything... – jordan.baucke Jan 04 '13 at 22:45
  • Since it fails for **all** invocations of `mvn` even those without a `pom.xml` file present, all it fails for **all** versions you've tried - it must be something in your environment that is somehow added to the `mvn` classpath.. – Peter Svensson Jan 04 '13 at 23:03
  • @PeterLiljenberg hmmm I have no idea what it could be... or how to fix it – jordan.baucke Jan 04 '13 at 23:16
  • I suggest troubleshooting this by switching to an earlier jdk, assuming you have it installed. See http://apple.stackexchange.com/questions/57986/multiple-java-versions-support-on-os-x-and-java-home-location for how to switch jdk on mac. – kldavis4 Jan 05 '13 at 01:06
  • @kldavis4 Nope, now down to java 1.6, same problem. I'm considering erasing my OS and reinstalling. – jordan.baucke Jan 07 '13 at 17:31
  • when you run mvn -X with java 1.6, what is the value of Java home? Is it: /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home ? – kldavis4 Jan 07 '13 at 18:51
  • The issue is that the maven classpath has the wrong version of guava in it. Maven should be using the MAVEN_HOME environment variable for building the classpath. If you look in MAVEN_HOME, the lib directory contains the core set of jars the maven runtime requires. There you should see a sisu-guava-0.9.9 jar. That is the correct version for Maven 3.0.4. Make sure there is nothing in the lib/ext directory. – kldavis4 Jan 07 '13 at 19:08

4 Answers4

3

The problem is the wrong set of the MAVEN_HOME variable cause it's pointing to a wrong folder

Maven home: /usr/local/Cellar/maven/3.0.4/libexec

Furthermore the installation your are using doesn't look like the default from maven.apache.org download page.

You should download the apache-maven-3.0.4-bin.tar.gz from maven.apache.org unpack it and point the MAVEN_HOME to the root of the extracted archive something like:

/usr/local/apache-maven-3.0.4

and put the bin folder /usr/local/apache-maven-3.0.4/bin into the PATH. If you call

mvn --version

something more or less similar like the following should be printed out:

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$ 
khmarbaise
  • 92,914
  • 28
  • 189
  • 235
2

It looks like the version of Maven you have installed has a dependency on an incorrect version of Guava. Maven 3 does apparently depend on Guice and Guava, so the error isn't totally spurious. This may be a problem with the Homebrew package that you are using having the incorrect library dependencies (it appears to be using 0.9.9 of Guava. You should raise this with the package maintainer and/or install a tarball / zip version instead of using Homebrew.

kldavis4
  • 2,177
  • 1
  • 22
  • 33
0

Faced a similar issue on OS X, with maven 3.2.2 and Java 1.8. 'mvn clean test' was failing with no class definition found error. Upgraded maven to 3.3.9 and was able to successfully run mvn commands.

excalibur
  • 31
  • 3
0

It could be that some of your jars would be having dependency on google/guava jars and if they're not in build path or if multiple of them are there it might raise inconsistency hence the error. A quick solution could be add latest version of guava to your pom

 <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>24.0-jre</version>
    </dependency>

Now check in dependency hierarchy if any of your Jar apart from guava is referring to any other older jar of guava/google-collections. If so then exclude it, something like this

<exclusions>
            <exclusion>
                <groupId>com.google.collections</groupId>
                <artifactId>google-collections</artifactId>
            </exclusion>
 </exclusions>
Saurabh Talreja
  • 335
  • 2
  • 6