java IntelliJ IDEA 和 Gradle:为什么每个子模块有 3 个模块?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36372571/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 01:20:35  来源:igfitidea点击:

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

javaintellij-ideagradle

提问by Fabian Zeindl

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

我对 IntelliJ IDEA 的 gradle 集成以及 gradle 子项目到 IDEA 模块的映射感到困惑。

  • 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.
  • 为什么每个 gradle 子项目(client、client_main 和 client_test)都有 3 个模块?
  • 有没有办法摆脱“父”模块?每次我删除它时,我的构建都会以令人困惑的方式中断。

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

在此处输入图片说明

回答by Sri Harsha Chilakapati

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.

现在可以在 IDEA 中导入 gradle 项目时取消选择该选项,在 2016.1.2 Ultimate IDE 中检查。首先转到导入 gradle 选项并选择您的 gradle 文件。

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.

然后在出现的对话框中,确保取消选择create separate module per source set的选项。这是默认选择的。现在继续像往常一样导入项目。

Gradle configuration dialog

Gradle 配置对话框

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.

就是这样,您可以享受您的项目,在多项目 gradle 构建中,将为每个子项目创建一个模块。

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.

仅当您在 gradle 中有一个单独的子项目用于像我这样的测试时,此选项才有用。否则,默认方式非常有效,因为我发现启动单元测试更容易。

Imported project, package view

导入的项目,包视图

Hope this helps.

希望这可以帮助。

回答by Robert Golusiński

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.

如果您只想为之前导入的项目禁用此选项,您可以通过编辑位于.idea/gradle.xml 中的idea gradle 配置文件来实现

Add this line that sets resolveModulePerSourceSetto false:

添加将resolveModulePerSourceSet设置为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.

然后刷新gradle项目。