Java – Add Guava to new Maven IntelliJ module

guavaintellij-ideajavamaven

I'm having trouble adding Google Guava to my IntelliJ project. I've tried the following:

  1. From pom.xml, using ALTINSERT and selecting "Dependency". I tried searching for "google", "guava", and "google-guava". There were no results for any of these searches.

  2. The guava website suggests that guava can be found in "Maven Central." I think that is http://repo1.maven.org/maven2/. I tried adding that URL to the list at Project Settings->Maven->Repositories. If I add it to the "Artifactory or Nexus Service URLs" list, when I click "Test" I get the message "No repositories found." I cannot find a way to add the URL to the list of "Indexed Maven Repositories" (which only has an "Update" button).

  3. I tried adding this <dependency> snippet directly to pom.xml

    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>10.0.1</version>
    </dependency>
    

    but com.google.guava gets highlighted in red with a tooltip saying that dependency cannot be found.

How can I get IntelliJ to add Guava as a maven dependency for my project (without downloading it myself)?

Edit

The Maven Repositories that IntelliJ is already configured with are:

The only entry in my "Indexed Maven Repositories" is a local directory:

  • /home/benw/.m2/repository

Best Answer

<dependency>
  <groupId>com.google.guava</groupId>
  <artifactId>guava</artifactId>
  <version>10.0.1</version>
</dependency>

this is what is working for me without any special configuration for IntelliJ with auto-import turned on for all my Maven projects. Without auto-import you have to tell IntelliJ to manually resolve the pom.xml changes.

Make sure you are not overriding the defaults in the pom.xml or the ~/.m2/settings.xml with a mirrors or other incorrect repository declarations.