Why my gradle projects creates separated modules for main and test in Intellij Idea

UPDATE:

It appears Jetbrains removed the checkbox I was referring to since I posted this. galcyurio's answer looks like the correct way to disable this functionality in current builds.

Original Answer:

You can turn this off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.

I had to turn it off as it was causing build failures because Make was only pulling in the main source set. This is likely a bug in Intellij because gradle can still build the projects just fine.


I have the same effect which is not what I expected especially as IntelliJ 14 Ultimate behaves completely different on the same project.

This is the new behavior of IntelliJ introduced with version 2016.1 to handle complex Gradle projects (which never worked completely before when you introduced new source sets).

It looks a little bit strange but works (better than before). And you can see the dependencies for each source set in the gradle project window now.

See also What's New in IntelliJ IDEA 2016.1 and Gradle Goodness: Source Sets As IntelliJ IDEA Modules.


Above 2019.2

I looked for intellij's settings here and there, but couldn't find options. So I checked the source of the community version on GitHub. This option is deprecated. Not sure, but it seems to be set invisible.

This setting is deprecated and remains only for troubleshooting since it's not fully compatible with Gradle's model. Please consider restoring it to the default (checked)

See lines 20-22 of this file.


Environment

  • IntelliJ IDEA 2017.2 (Build #IU-172.3317.76, built on July 15, 2017)
  • Windows 10
  • Gradle project

Trouble shooting

In my case, I cannot find the option which 'Alex Spence' mentioned.

You can turn this off in Gradle Settings. Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle: uncheck create separate modules per source set.

I searched about that option, fortunately a lot of other answers showed me where is that option.

  • IntelliJ IDEA and Gradle: Why there are 3 modules per sub-module?
  • Control automatic creation of IDEA modules from Gradle sourceSets in 2016.1?

Solution

We can uncheck this option when we import or create module and import project.

when import project

  • File -> New -> Project from existing sources... -> select file -> Gradle -> uncheck create separate modules per source set
  • Welcome page -> Import project -> select file -> Gradle -> uncheck create separate modules per source set

when import module

  • Project Structure -> Add -> import module -> select file -> Gradle -> uncheck create separate modules per source set

when create new module

  • You can also uncheck this option when you create new module.