IntelliJ IDEA and Gradle: Why there are 3 modules per sub-module?

If you want to just disable this option for a previously imported project you can do so by editing idea gradle configuration file located in .idea/gradle.xml.

Add this line that sets resolveModulePerSourceSet to false:

<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
  ...
  <component name="GradleSettings">
    <option name="linkedExternalProjectsSettings">
      <GradleProjectSettings>
        ...
        <option name="resolveModulePerSourceSet" value="false" />
      </GradleProjectSettings>
    </option>
  </component>
</project>

And then refresh the gradle project.


It is now possible to deselect that option when importing the gradle project in IDEA, checked in 2016.1.2 Ultimate IDE. First go to the import gradle option and select your gradle file.

Project Import Dialog

Then in the dialog that appears, make sure you deselect the option that says create separate module per source set. This is selected by default. Now continue with importing the project as you normally would.

Gradle configuration dialog

And that's it, you can enjoy your project, just one module will be created for each sub project in the multi project gradle build.

This option is only useful if you are having a separate sub project in gradle for the tests like me. Otherwise, the default way works pretty much good, as I found it more easy to launch unit tests.

Imported project, package view

Hope this helps.