Source Directories Not Being Created In New Project

Answered

If I create a new project using gradle from IDEA the directory structure (src/main/java etc) is not created.
However, if I do gradle init --type java-library everything is.

There are a few more comments in  the files too.

3
9 comments
Official comment

Since 2019.2 IDE versions the directories are only automatically created when you create new module or new project and select to enable corresponding Gradle plugins e.g.

src/main/java
etc

for java Gradle module

src/main/groovy
etc

for groovy Gradle module.

It seems the only case when one needs for the directories to be auto-created when working in IDE.

In the existing project if you add a plugin and want new directories to be created there is an action that lets you create all the directories at once:

 

There is a problem however that if initial project creation process fails (when Gradle build fails for some reason) the directories will not be created automatically. Here is the related issue for this: https://youtrack.jetbrains.com/issue/IDEA-216490

Check idea.log for errors (https://intellij-support.jetbrains.com/entries/23352446).

Make sure this option is enabled:

http://i.imgur.com/E9urg2u.png

After the import completes, empty folders are created and configured as sources/test sources (tested with 14.1.4):

http://i.imgur.com/XgrL3oJ.png

3

Thank you, but how do you change it if you didn't set it initially when the project was created?

1

Or you can find the same configuration value under settings -> gradle (if you are using gradle), which solved my problem.

 

3

In fact the answer by @Tom Stachura is far more correct. I had the same issue (i.e. created the Kotlin project using the Wizard but forgot to click the option and tried to retro-fit it) and I followed his suggestion and if you look you will see that once the setting to "Create directories for empty content..." is set, Gradle build will run and it will create sub modules as follows...I never got to grips with the module concept so I rather Gradle does that and sorts out the project structure and dependencies:

For any newbies, you get to the option on Windows with: Ctl-Alt-s

You will then see the option here:

3

The solution is given by @Tom Stachura works like a charm! Since I am a newbie I had a tough time to find out what went wrong. Anyways, now it works. Thanks again!

0

Unfortunately, JetBrains removed this options from the gradle settings dialog (at least in IU), and there seems to be no other way now to do this now.

Since it once obviously worked, I have a really hard time understanding why such a useful feature was removed. =: (

4

Yes, couldn't agree more.  A fugitive from Eclipse here. IntelliJ looks promising, but my God, the chopping and changing that appears to have gone on over, seemingly, fairly recent time, makes this a v. steep learning curve.

I just created a Module under a Project (at the moment I still only have a vague understanding of why IntelliJ can't just have "projects" in a "workspace" like all other IDEs). I specified Gradle. Previous modules specified with Gradle built the structure (src/main/java, src/test/java, and src/main/groovy and src/test/groovy if Groovy checked). This time it did nothing of the sort... and that "Create directories from ... " option is NOWHERE TO BE FOUND.

Version: 2020.1 CE.

Later: I just did the same thing: created an "empty" project... and created a new module, stipulating "Gradle", with JDK Java 11, and "Groovy" checked.  This time, for some unaccountable reason, it did create the directory structure correctly, when I first selected the new "ModuleA". Puzzlement.

0

Please sign in to leave a comment.