23

I am rather confused by IntelliJ IDEA's gradle integration and the mapping of gradle subprojects to IDEA's modules.

  • Why are there 3 modules for every gradle subproject (client, client_main and client_test)?
  • Is there a way to get rid of the "parent" module? Every time I delete it my build breaks in confusing ways.

Project Structure

UPDATE

  • The content root of the third module ("server") is always set to the entire folder like seen below. This means I can't mark directories in build as generated sources, since the are excluded by default.

enter image description here

denov
  • 11,180
  • 2
  • 27
  • 43
Fabian Zeindl
  • 5,860
  • 8
  • 54
  • 78

2 Answers2

22

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.

Sri Harsha Chilakapati
  • 11,744
  • 6
  • 50
  • 91
15

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.