在 IntelliJ IDEA 中使用 Gradle 的 Java 项目:无法解析符号“google"但项目可以编译 [英] Java project with Gradle in IntelliJ IDEA: cannot resolve symbol 'google' but project compiles

查看:99
本文介绍了在 IntelliJ IDEA 中使用 Gradle 的 Java 项目:无法解析符号“google"但项目可以编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 IntelliJ IDEA 13.1.2 中使用 Gradle 设置了一个玩具 Java 项目.它编译并运行良好,但 IDE 在

I have a toy Java project set up with Gradle in IntelliJ IDEA 13.1.2. It compiles and runs fine, but the IDE highlights 'google' in

import com.google.common.base.Strings;

为红色并警告无法解析符号 'google'".知道如何修复它吗?

as red and warns "Cannot resolve symbol 'google'". Any idea how to fix it?

我尝试过 1) 删除 .idea/ 并在 IntelliJ IDEA 中重新创建项目,以及 2) 从手动创建的 Gradle 配置文件 build.gradle<中重新导入项目/code>,但无济于事.

I have tried 1) deleting .idea/ and re-creating the project in IntelliJ IDEA, and 2) re-importing project from the manually created Gradle configuration file build.gradle, but to no avail.

推荐答案

原来除了 build.gradle 之外,IntelliJ IDEA 中还需要单独指定依赖包,并显式添加为依赖性.也就是说,

It turns out that the depended packages need to be separately specified in IntelliJ IDEA in addition to build.gradle and explicitly added as a dependency. Namely,

  1. 按照com.google.guava包rel="nofollow">文档中的说明 -- 我选择了 com.google.guava:guava-base:r03 下载
  2. 按照自动提示的窗口将其作为项目库添加​​到 Java 项目中.
  3. 在项目设置中指定 Java 模块依赖于 com.google.guava 包.请参阅文档说明 "配置模块依赖项和库".
  1. download the com.google.guava package following the instruction in documentation -- I picked com.google.guava:guava-base:r03 to download
  2. follow the automatically-prompted window to add it as a project library to the Java project.
  3. Specify that the Java module depends on the com.google.guava package in the project settings. See the documentation instruction "Configuring Module Dependencies and Libraries".

这篇关于在 IntelliJ IDEA 中使用 Gradle 的 Java 项目:无法解析符号“google"但项目可以编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆