IntelliJ无法识别Gradle项目中的某些导入 [英] IntelliJ won't recognize some imports from gradle project

查看:1443
本文介绍了IntelliJ无法识别Gradle项目中的某些导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在IntelliJ中执行Gradle项目,并且IntelliJ无法识别某些软件包.当我转到项目结构->模块-> <my module>->依赖关系时,包含这些包的jar文件就在其中. (我已经用jar tfv <file>检查了jar文件,以确保有问题的类在文件中.)

I am working on a Gradle project in IntelliJ and some packages are not recognized by IntelliJ. When I go to Project Structure -> Modules -> <my module> -> Dependencies, the jar file that contains these packages is there. (I've examined the jar file with jar tfv <file> to make sure that the classes in question are in the file.)

有问题的类为红色,将它们悬停在它们上时,出现诸如无法解析符号'somepackagename'"或无法解析符号'SomeClassName'"之类的错误.

The classes in question are in red and when hovering over them, I get errors like "Cannot resolve symbol 'somepackagename'" or "Cannot resolve symbol 'SomeClassName'".

但是,gradle项目可以从命令行正常编译.

However, the gradle project compiles just fine from the command line.

我已经尝试了所有可以找到的现有建议,但是到目前为止,没有任何帮助.首先,我已经尝试过:

I've tried all the existing suggestions I could find, but so far none have helped. Primarily, I've already tried:

  • 删除.idea文件夹并重新导入
  • 从root build.gradle文件重新导入项目
  • 点击刷新所有gradle项目"按钮
  • 升级IntelliJ
  • 单击使缓存无效并重新启动"

如何使IntelliJ识别这些jar文件中的软件包?

What can I do to get IntelliJ to recognize the packages in these jar files?

推荐答案

我遇到了同样的问题.我的IntelliJ无法识别来自build.gradle的某些依赖项.我的猜测是它是一个缓存的东西.所以我做了以下事情:

I had the same problem. My IntelliJ didn't recognize some dependencies from the build.gradle. My guess is that its a cache thing. So I did the following:

  1. 删除gradle缓存目录.

  1. Delete the gradle caches directory.

rm -rf ~/.gradle/caches

  • 重新启动IntelliJ并刷新gradle依赖项.

  • Restart IntelliJ and refresh gradle dependencies.

    这对我有用,似乎是一个简单的解决方案.

    This worked for me and seems like a simple solution.

    这篇关于IntelliJ无法识别Gradle项目中的某些导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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