Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

src folder not created when creating simple Intellij java gradle Project

I am following the instructions to create a simple IntelliJ Project with Gradle support and the src folder is not created (I guess this is the base of any Java Project) https://www.jetbrains.com/help/idea/getting-started-with-gradle.html

  1. New Project: I check Gradle and Java - next
  2. Added Artefact ID -> next
  3. "Use auto-import", "using explicit module groups", "create separate Module per source set", "Use default Gradle wrapper" -> next
  4. Give a project name -> next

I have no src folder. I am not able to add a new class.

enter image description here

When doing the same without gradle I have the src folder.

UPDATE Adding a module called "src" works, but then I have a module called src and a folder in it called src. But this is a hack. Just bought IntelliJ for 200 bucks and I hope this can be solved in a more professional way :-)

like image 837
mcfly soft Avatar asked Apr 07 '18 17:04

mcfly soft


People also ask

How do I get the src folder in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules. Select the necessary module and open the Sources tab. next to Source Folders or Test Source Folders. Specify the package prefix and click OK.

What is src folder in Java project?

Describes the Java™ source tree. When you create an API project, it is set up as a Java project with separate folders for source and class files. The source folder is named src .

How do I create a Gradle project in IntelliJ?

Open your project in IntelliJ IDEA. In the Project tool window, right-click the name of your project and select New | File. In the dialog that opens enter build. gradle and click OK.


3 Answers

For Windows the solution is. To go manually into: File -> Settings -> Build, Execution, Deployment -> Gradle -> check the "Create directories for empty content roots automatically".

For Mac the solution is. To go manually into: Intellij IDEA -> Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> check the "Create directories for empty content roots automatically".

like image 97
mcfly soft Avatar answered Oct 17 '22 08:10

mcfly soft


Just right create on your project directory and choose New -> Directory -> (choose all four to be created: src/main/java, src/main/resource, src/test/java, and src/test/resource) -> enter

right click on project directory

choose the four choices

found the answer here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206806425-Source-Directories-Not-Being-Created-In-New-Project

like image 40
ASB Avatar answered Oct 17 '22 08:10

ASB


@here A quick fix that worked for me. Once you have created the gradle project as mentioned in the question

  • open the gradle sidebar on the right hand side.
  • click settings
  • a new dialog box will appear.
  • In this dialog box check the option "create directories for empty contents roots automatically"
  • then click apply and src folders will be created for you ..

Images are attached for clarity.

Open the gradle sidebar on the right hand side.

Check the option "create directories for empty contents roots automatically"

like image 12
Rehan Avatar answered Oct 17 '22 06:10

Rehan