I have had this issue multiple times, specially when importing a new project. In my case, there are projects based on spring-boot that includes multiples dependencies that causes Intellij to go mad the first time you import it.
As other answers here are valid, to know which one will suit better in your case, first check the log on Intellij:
~/.cache/JetBrains/IntelliJIdea202X.X/log
Where the folder must match your current Intellij version. Here in some cases I have noticed some issues with some plugins that are causing some exceptions (in my case Checkstyle). Disabling the plugin, and invalidating the cache and restarting has solved the issue.
In other cases, I notice the classical:
Caused by: java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
On the logs, but it is not reflected on the Intellij UI.
Where increasing the heap memory of the project on Intellij settings Build, Execution, Deployment -> Compiler -> Shared build process heap size can solve it as commented in others answers
Last case, I have a:
SEVERE - #o.j.i.maven - java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space
That is more related to when Maven refresh the dependencies. If is the case, Change on Build, Execution, Deployment -> Build Tools -> Maven -> Importing -> VM options for importer: and set it to -Xmx2g or any other value.
Other example is Build, Execution, Deployment -> Build Tools -> Maven -> Runner -> VM options: and set it to -Xmx4g or any other value.
Other option sometimes is to delete the cache and configuration from Intellij. According to this link, Intellij uses some directories where the cache is stored. Remove the next directory when intellij is not running:
~/.cache/JetBrains/<product><version>
And start it. Check now if it works.
In any case, remember to check the log or you can spent several hours by trial and error with all the answers posted here. I have put some memory settings that must be adapted to your machine specifications. Do not copy and paste it blindly.