IntelliJ IDEA中具有Gradle的Java项目:无法解析符号"google",但项目可以编译 [英] Java project with Gradle in IntelliJ IDEA: cannot resolve symbol 'google' but project compiles
问题描述
我在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,
- 按照文档-我选择了
com.google.guava:guava-base:r03
下载 - 遵循自动提示的窗口,将其作为项目库添加到Java项目中.
- 在项目设置中指定Java模块依赖于
com.google.guava
包.请参阅文档说明配置模块依赖关系和库" .
- download the
com.google.guava
package following the instruction in documentation -- I pickedcom.google.guava:guava-base:r03
to download - follow the automatically-prompted window to add it as a project library to the Java project.
- 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屋!