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

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

问题描述

我在IntelliJ IDEA 13.1.2中使用Gradle设置了一个玩具Java项目.它可以编译并正常运行,但是IDE会在其中突出显示"google"

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重新导入项目,但无济于事.

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: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天全站免登陆