[英]Java project with Gradle in IntelliJ IDEA: cannot resolve symbol 'google' but project compiles
I have a toy Java project set up with Gradle in IntelliJ IDEA 13.1.2.我在 IntelliJ IDEA 13.1.2 中使用 Gradle 设置了一个玩具 Java 项目。 It compiles and runs fine, but the IDE highlights 'google' in
它编译并运行良好,但 IDE 在
import com.google.common.base.Strings;
as red and warns "Cannot resolve symbol 'google'".为红色并警告“无法解析符号‘谷歌’”。 Any idea how to fix it?
知道如何修复它吗?
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.我尝试过 1) 删除
.idea/
并在 IntelliJ IDEA 中重新创建项目,以及 2) 从手动创建的 Gradle 配置文件build.gradle
重新导入项目,但无济于事。
I think user Sap is correct, at least in my case.我认为用户 Sap 是正确的,至少在我的情况下是这样。 You should not have to manually add the dependency.
您不必手动添加依赖项。
Did you change the dependencies in the gradle file without syncing intellij?您是否在不同步 intellij 的情况下更改了 gradle 文件中的依赖项? Try this button:
试试这个按钮:
For more information, see: https://www.jetbrains.com/idea/help/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html有关更多信息,请参阅: https : //www.jetbrains.com/idea/help/synchronizing-changes-in-gradle-project-and-intellij-idea-project.html
You can simply open Gradle tool window at [ View
] - [ Tool Windows
] - [ Gradle
].您可以简单地在 [
View
] - [ Tool Windows
] - [ Gradle
] 打开 Gradle 工具窗口。
In the window, you can refresh by clicking refresh button.在窗口中,您可以通过单击刷新按钮进行刷新。
All dependencies manually added directly into build.gradle
file will be resolved.直接手动添加到
build.gradle
文件中的所有依赖build.gradle
都将得到解决。
One of the solutions that worked for me after trying everything listed on the internet to solve this issue was to install the lombok plugin.在尝试了互联网上列出的所有内容来解决此问题后,对我有用的解决方案之一是安装 lombok 插件。
Got to File --> Settings --> Plugins and look for Lombok.转到文件 --> 设置 --> 插件并查找 Lombok。
Make sure the "Enable annotation processing" is ticked确保勾选“启用注释处理”
我的 Gradle 项目使用的是 Intellij 2019.2.3, File->Invalid Cache/Restart...
不起作用,但View->Tool Windows->Gradle->sync(the circular icon)
立即起作用。
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.原来除了
build.gradle
,依赖包还需要在IntelliJ IDEA中单独指定,并显式添加为依赖。 Namely,即,
com.google.guava
package following the instruction in documentation -- I picked com.google.guava:guava-base:r03
to download com.google.guava
包 - 我选择com.google.guava:guava-base:r03
下载com.google.guava
package in the project settings.com.google.guava
包。 See the documentation instruction "Configuring Module Dependencies and Libraries" .In my case, I have to do the following:就我而言,我必须执行以下操作:
You can find your idea.system.path
here: https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs您可以在此处找到您的
idea.system.path
: https : idea.system.path
-插件和日志
在我的情况下(Apache Beam 来源)需要一个./gradlew clean
。
在我的案例中,我已经将 Gradle 版本(模块:项目)从 3.2.2 更新到 3.5.2,而且 NDK 文件位置存在问题,它位于错误的路径上,我刚刚将其切换为默认 NDK 路径,然后使项目无效并重新启动。
What helped me was checking "dependencies" in "project settings/modules" section.帮助我的是检查“项目设置/模块”部分中的“依赖项”。 Apparently, Idea did not pick up them correctly.
显然,Idea 没有正确地捡起它们。
Steps which worked for me:对我有用的步骤:
This trick helped me to get modules with correct dependencies generated.这个技巧帮助我获得了生成正确依赖项的模块。 Probably it happened because initially, I imported the project as non-Gradle one.
可能是因为最初,我将该项目作为非 Gradle 项目导入。
I was having the wrong import.Check if you have right import.我导入错误。检查您是否正确导入。 In case you have imported using:
如果您使用以下方式导入:
import org.junit.Test
and you have org.junit.jupiter.api.Test
in class path, try importing with :并且您在类路径中有
org.junit.jupiter.api.Test
,请尝试导入:
import org.junit.jupiter.api.Test;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.