mcfly soft
mcfly soft

Reputation: 11645

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 :-)

Upvotes: 54

Views: 61093

Answers (7)

ASB
ASB

Reputation: 474

Just right-click on your project directory and choose New -> Directory.
Select all four to be created.

  1. src/main/java
  2. src/main/resource
  3. src/test/java
  4. src/test/resource

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

Upvotes: 36

Tri Dawn
Tri Dawn

Reputation: 780

As of January 2022 with Intellij IDEA 2021.1.3 and Gradle 6.8

First of all, right-click your project main folder ...

First Step

Go to > New > Directory...

Second Step

After clicking the "Directory" option, this will open a dialog containing available options of "Gradle Source Sets" to add.

Third Step

You can select what "Gradle Source Sets" you want to add. In my case, I have already added the "src/main/kotlin" (Notice it's not displayed in the options).

Upvotes: 5

sososocke
sososocke

Reputation: 29

Add a directory named 'src'. Right click on it and then click Mark Directory as Sources Root.

Upvotes: 2

justAnotherGuy
justAnotherGuy

Reputation: 387

None of the above worked for me. Finally, had to go raw.

gradle init --type java-library

Followed Mkyong's page on gradle init

Then, simply 'Open' project in Intellij. Then updated project settings related to JAVA_HOME and Gradle home (Chances are these were related to my specific installation).

Upvotes: 2

Richard Shin
Richard Shin

Reputation: 31

If enabling the "Create directories for empty content roots automatically" setting does not show the src directory, check the project structure and try creating and deleting a dummy module.

  1. File -> Project Structure -> Modules -> Project Name -> Confirm that src is part of the hierarchy and exit out of the pop up
  2. Right click on the root folder of the project -> New -> Module
  3. The IDE may have refreshed, along with the visibility of the src folder

Upvotes: 3

mcfly soft
mcfly soft

Reputation: 11645

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".

Upvotes: 66

Rehan
Rehan

Reputation: 121

@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"

Upvotes: 12

Related Questions