7
votes

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

  1. From pom.xml, using ALT-INSERT 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
3

3 Answers

9
votes
<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.

3
votes
  1. ALT-INSERT works with dependecies you already have in local repository.
  2. http://repo1.maven.org/maven2 can not be browsed, but correct link to artifacts works. E.g. try guava 10.0.1
  3. After adding dependency snippet you should reimport Maven project. For exmaple your snippet
<dependency>
    <groupId>com.google.guava</groupId>
    <artifactId>guava</artifactId>
    <version>10.0.1</version>
</dependency>

works for me successfully.

2
votes

I believe Maven itself (by default) pulls from Maven Central automatically if it does not already have a particular artifact in the local repository. So all you should need to do is ensure that IDEA is pointing to "/home/benw/.m2/repository" as your local repository and that there aren't any changes in "/home/benw/.m2/settings.xml" that would be preventing Maven from accessing Central.