Java file outside of source root intelliJ
Very simple solution :-
Click on "maven" on the right toolbar in IntelliJ and then click on the refresh button.
This has been driving me quite mad and I am a newbie as well. I finally solved it by using:
file > project structure >
Then going to Modules and removing all the files from the root using the x marks on the far right. I then used the +Add Content Root to reselect the src folders that contained my .java and hit Apply. Finally InteliJ sees the files as in the project and the folders gain the blue square on the main view.
If you do an 'import from git', IntelliJ doesn't import the project structure from maven (or gradle) automatically.
One way to do this afterwards is to right-click on the pom.xml file in the root directory, and select 'Add as maven project'. Then the folders will be marked correctly, and dependent libraries will be imported. There should be no need to mark individual source folders manually.
I prefer to do a git clone outside of IntelliJ, and afterwards open the project in IntelliJ from the local filesystem, then IntelliJ imports the maven project structure automatically.
I fixed it using this way:
File > Project Structure > Modules > Sources
and then marked java files dir as Sources.