Add Guava to the new Maven IntelliJ module

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

  • From pom.xml using ALT - INSERT and choosing Dependency. I tried to find "google", "guava" and "google-guava". There were no results for any of these searches.

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

  • I tried adding this <dependency> fragment directly to pom.xml

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

    but com.google.guava is highlighted in red with a tooltip that says the dependency cannot be found.

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

Edit

Maven repositories that are already configured by IntelliJ are as follows:

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

  • /home/benw/.m2/repository
+6
source share
3 answers
 <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>10.0.1</version> </dependency> 

this is what works for me without any special configuration for IntelliJ with auto-import enabled for all my Maven projects. Without automatic import, you must tell IntelliJ to manually allow pom.xml changes.

Make sure that you do not override the default values ​​in pom.xml or ~/.m2/settings.xml with mirrors or other incorrect repository declarations.

+6
source
  • ALT - INSERT works with dependencies that you already have in the local repository.
  • http://repo1.maven.org/maven2 is not visible, but the correct link to artifacts works. For instance. try guava 10.0.1
  • After adding the dependency fragment, you must reimport the 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.

+3
source

I believe that Maven itself (by default) automatically retrieves from Maven Central if it does not already have a specific artifact in the local repository. Therefore, all you have to do is make sure that IDEA points to "/home/benw/.m2/repository" as your local repository and that there are no changes to "/home/benw/.m2/settings.xml" this will prevent Maven from accessing Central.

+2
source

Source: https://habr.com/ru/post/900543/


All Articles