Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ won't recognize some imports from gradle project

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.)

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'".

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:

  • Deleting the .idea folder and re-importing
  • Reimporting the project from the root build.gradle file
  • Clicking on the "Refresh all gradle projects" button
  • Upgrading IntelliJ
  • Clicking on "Invalidate Caches and Restart"

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

like image 486
Chris Middleton Avatar asked Nov 14 '18 20:11

Chris Middleton


3 Answers

The issue still occurs on IntelliJ IDEA 2021.3.2 (Community Edition). Invalidate Caches/Restart did not work, this solved it:

  1. Delete the .idea folder
  2. Close and open the project
like image 65
mementoGuy Avatar answered Sep 27 '22 20:09

mementoGuy


I also experience this problem on multi-project Gradle builds, it's still reproducible with the latest (at the moment of writing) IntellijIDEA 2020.3.2. It looks like some kind of internal caching issue, because even though IDEA complains it can't recognize the classes it can execute the build successfully.

Initially I was fixing it by invalidating caches and restarting IDEA, as had been suggested here, but then discovered that it goes away if I reload the project in Gradle Tool Window:

enter image description here

For me it works every time.

like image 9
curd0 Avatar answered Oct 19 '22 02:10

curd0


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. Delete the gradle caches directory.

    rm -rf ~/.gradle/caches
    
  2. Restart IntelliJ and refresh gradle dependencies.

This worked for me and seems like a simple solution.

like image 6
amay Avatar answered Oct 19 '22 04:10

amay