【问题标题】:Maven Guava Dependency "Cannot resolve symbol 'google'" in IntelliJ IDEAIntelliJ IDEA 中的 Maven Guava 依赖“无法解析符号‘google’”
【发布时间】:2017-05-14 19:29:18
【问题描述】:

IntelliJ 说 无法解析符号 'google'。 关于此导入:

import com.google.common.cache.LoadingCache;

即使我已经正确添加了依赖并且它没有抱怨它:

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

我已经更新了我的 Maven 存储库。我在 IntelliJ IDEA 中启用了 Maven 自动导入。我的项目使用的是 SDK 1.8 版。根据网络上的大量示例,这应该有效,但它没有。

我发现this 有类似的情况(尽管不是同一个问题,因为我的代码无法编译)。我尝试使缓存无效并重新启动,但没有帮助。最佳答案还建议删除IDEA系统目录。我不知道这是否是个好主意,如果我这样做会破坏多少东西。

【问题讨论】:

  • 如果它是“唯一”IntelliJ thay 搞砸了,通常使缓存无效并重新导入 Maven 项目可以解决问题
  • 重新导入项目并多次使缓存无效似乎已经破坏了一切。现在它对所有事情都说“无法解决”! :(
  • @AtteJuvonen 你能尝试从命令行构建 maven 吗?

标签: maven intellij-idea guava google-guava-cache


【解决方案1】:

我遇到了同样的问题,正在尝试所有解决方案来导入 Guava 缓存管理器。

但我犯的错误是,没有正确添加依赖项。请在尝试任何解决方案之前检查 pom.xml。

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

【讨论】:

    【解决方案2】:

    如果其他人有类似的问题,阅读 pom.xml 可能会有所帮助。原来我定义了两次&lt;properties&gt;。由于某种原因,在添加 Guava 依赖项之前它没有引起问题。删除重复的定义后,一切又开始工作了。

    【讨论】:

      猜你喜欢
      • 2020-12-29
      • 1970-01-01
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 1970-01-01
      • 2015-09-17
      • 2019-02-21
      • 1970-01-01
      相关资源
      最近更新 更多