简体   繁体   中英

Maven Guava Dependency “Cannot resolve symbol 'google'” in IntelliJ IDEA

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.

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.

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>`

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM