Why does IntelliJ give me "Package doesn't exist" error?

Just reimport didn't work. Following worked for me.

File -> Invalidate Caches /Restart

Then

Build -> Rebuild Project

That will reimport maven project.

Note : You need to invalidate the cache AND ALSO rebuild the project.


I tried to "Maven > Reimport" but the only thing that actually fixed it was to close the project, delete the .idea directory, and reopen the project.


Right click your project / Maven (at bottom) / Reimport

Edit, much later: I also saw this happen much more frequently when I had the Clover plugin installed. Drop that plugin like a bad habit!


None of the 13 existing answers worked for me. However, I could resolve the issue by first removing all modules:

  1. open File > Project Structure...,
  2. go to Modules tab,
  3. select all modules and press the remove button,

then removing all remaining Maven modules from Maven tool window:

  1. select all modules,
  2. right click on them,
  3. press Remove projects,

and then adding them again in Project tool window:

  1. right click on root pom.xml,
  2. press Add as Maven project,

now unignoring any ignored modules from Maven tool window:

  1. select all ignored (grey) Maven modules,
  2. right click on them,
  3. press Unignore,

and finally rebuilding using Build > Rebuild project. This assumes that a mvn clean install already happened.