This problem happens intermittently for different libraries and different projects. When trying to import a library, the package will be recognized, but the class name can\'
I had this recently while trying to use Intellij to work on NiFi, turned out the issue was that NiFi requires Maven >= 3.1.0 and the version that I'd checked out with (I guess my default) was 3.0.5. Updating the Maven version for the project fixed it, so in some cases Maven version mis-alignment can be a thing to look...I'd guess it's fairly unusual but if you get this far on the thread you're probably having an unusual issue :)
file
-> Project Structure
-> Modules
, find the module with problems, click it and choose the Dependencies
tab in the right side. Click the green plus sign, try to add the jar or libraries that cause the problem. That works for me.
I had a similar issue with my imported Maven project. In one module, it cannot resolve symbol on import for part of the other module (yes, part of that module can be resolved).
I changed "Maven home directory" to a newer version solved my issue.
Update: Good for 1 hour, back to broken status...
File -> Invalidate Caches/Restart or rebuilding the project did not work wor me.
What worked for my Gradle project was to "Refresh all Gradle projects" from the Gradle tab on top-right corner of IntelliJ v2017, using the yellow marked button shown below:
After a long search, I discovered that a dependency was somehow corrupted on my machine in a maven project. The strange thing was that the dependency was still working correctly in the compiled java code. When I cleaned and rebuilt my maven dependency cache however, the problem went away and IntelliJ recognized the package. You can do this by running:
mvn dependency:purge-local-repository
Intrestingly, the source of my problem hence wasn't IntelliJ, but maven itself.