Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 663
Fabian Zeindl Avatar asked Apr 02 '16 11:04

Fabian Zeindl


2 Answers

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.

like image 155
Sri Harsha Chilakapati Avatar answered Dec 10 '22 23:12

Sri Harsha Chilakapati


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.

like image 21
Robert Golusiński Avatar answered Dec 10 '22 23:12

Robert Golusiński