Maven Guava Dependency "Cannot resolve symbol 'google'" in IntelliJ IDEA

6.7k views Asked by At

IntelliJ says Cannot resolve symbol 'google'. about this import:

import com.google.common.cache.LoadingCache;

Even though I have added the dependency correctly and it doesn't complain about it:

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

I have updated my Maven repository. I have Maven auto-import enabled in IntelliJ IDEA. My project is using SDK version 1.8. Based on numerous examples on the web, this should work, but it doesn't.

I found this about a similar (although not the same issue, as my code doesn't compile). I tried invalidating the cache and restarting, but it didn't help. The top answer also suggests deleting the IDEA system directory. I don't know if this is a good idea and how much stuff breaks if I do that.

2

There are 2 answers

0
bkoodaa On

If anyone else has a similar issue, reading through pom.xml may be helpful. Turns out I had <properties> defined twice. For some reason it was not causing problems before adding the Guava dependency. After removing the duplicate definition, everything started working again.

0
Hema On

I had the same problem and was trying all solutions to import Guava cache manager.

But the mistake I made was, did not add dependencies properly. Please do check pom.xml before trying any solution.

   <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>25.0-jre</version>
    </dependency>
    <!-- these are the dependencies i missed -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context-support</artifactId>
        <version>4.3.10.RELEASE</version>
    </dependency>`