Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java file outside of source root intelliJ

I have cloned a spring boot project from GitLab having multiple branches in IntelliJ. I checkout to the branch in which I want to work. But I am getting "Java file outside of source root" on all the files. Please suggest what I am doing wrong. I just installed IntelliJ and it's the first project that I am importing.

like image 520
Abhishek Avatar asked Aug 21 '20 10:08

Abhishek


People also ask

Where is source root in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Project Settings | Modules. Select the necessary module and then open the Sources tab in the right-hand part of the dialog. Click Add Content Root and specify the folder that you want to add as a new content root. ).

What is source root in IntelliJ?

Sources Root - this is where your actual project code goes - typically in src/main/scala (though you can change that, or add extra source directories in your build). Directories nested below this level should be packages. Intellij needs to know these are sources so it can highlight them, check them for errors, etc.

How do I change the source in IntelliJ?

Module language level From the main menu, select File | Project Structure Ctrl+Alt+Shift+S . Under Project Settings, select Modules | Sources. From the Language level list, select the necessary option. To use the project language level, select Project default.


4 Answers

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.

like image 179
GeertPt Avatar answered Oct 17 '22 11:10

GeertPt


Very simple solution :-

Click on "maven" on the right toolbar in IntelliJ and then click on the refresh button.

like image 28
Hentai Ousama Avatar answered Oct 13 '22 18:10

Hentai Ousama


Very simple solution :-

Click on "maven" on the right toolbar in IntelliJ and then click on the refresh button.

like image 49
Hokkyokusei Avatar answered Oct 17 '22 10:10

Hokkyokusei


I fixed it using this way:

File > Project Structure > Modules > Sources

and then marked java files dir as Sources.

like image 38
Sunny Gupta Avatar answered Oct 17 '22 11:10

Sunny Gupta