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:
What can I do to get IntelliJ to recognize the packages in these jar files?
The issue still occurs on IntelliJ IDEA 2021.3.2 (Community Edition). Invalidate Caches/Restart did not work, this solved it:
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:

For me it works every time.
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:
Delete the gradle caches directory.
rm -rf ~/.gradle/caches
Restart IntelliJ and refresh gradle dependencies.
This worked for me and seems like a simple solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With