创建简单的 Intellij java gradle 项目时未创建 src 文件夹

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49710330/
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-08-12 03:06:16  来源:igfitidea点击:

src folder not created when creating simple Intellij java gradle Project

javagradleintellij-idea

提问by mcfly soft

I am following the instructions to create a simple IntelliJ Project with Gradle support and the src folder is not created (I guess this is the base of any Java Project) https://www.jetbrains.com/help/idea/getting-started-with-gradle.html

我正在按照说明创建一个具有 Gradle 支持的简单 IntelliJ 项目,但未创建 src 文件夹(我猜这是任何 Java 项目的基础) https://www.jetbrains.com/help/idea/getting-started -with-gradle.html

  1. New Project: I check Gradle and Java - next
  2. Added Artefact ID -> next
  3. "Use auto-import", "using explicit module groups", "create separate Module per source set", "Use default Gradle wrapper" -> next
  4. Give a project name -> next
  1. 新项目:我检查 Gradle 和 Java - 接下来
  2. 添加了 Artefact ID -> 下一个
  3. “使用自动导入”、“使用显式模块组”、“为每个源集创建单独的模块”、“使用默认 Gradle 包装器”-> 下一步
  4. 给一个项目名称->下一步

I have no src folder. I am not able to add a new class.

我没有 src 文件夹。我无法添加新课程。

enter image description here

enter image description here

When doing the same without gradle I have the src folder.

在没有 gradle 的情况下做同样的事情时,我有 src 文件夹。

UPDATEAdding a module called "src" works, but then I have a module called src and a folder in it called src. But this is a hack. Just bought IntelliJ for 200 bucks and I hope this can be solved in a more professional way :-)

更新添加一个名为“src”的模块有效,但是我有一个名为 src 的模块和一个名为 src 的文件夹。但这是一个黑客。刚刚花了 200 美元买了 IntelliJ,我希望能以更专业的方式解决这个问题:-)

采纳答案by mcfly soft

For Windowsthe solution is. To go manually into: File -> Settings -> Build, Execution, Deployment -> Gradle -> check the "Create directories for empty content roots automatically".

对于 Windows,解决方案是。手动进入:文件 -> 设置 -> 构建、执行、部署 -> Gradle -> 选中“自动为空内容根创建目录”。

For Macthe solution is. To go manually into: Intellij IDEA -> Preferences -> Build, Execution, Deployment -> Build Tools -> Gradle -> check the "Create directories for empty content roots automatically".

对于 Mac,解决方案是。要手动进入:Intellij IDEA -> 首选项 -> 构建、执行、部署 -> 构建工具 -> Gradle -> 选中“自动为空内容根创建目录”。

回答by user3133668

@here A quick fix that worked for me. Once you have created the gradle project as mentioned in the question

@here 一个对我有用的快速修复。一旦您按照问题中提到的方式创建了 gradle 项目

  • open the gradle sidebar on the right hand side.
  • click settings
  • a new dialog box will appear.
  • In this dialog box check the option "create directories for empty contents roots automatically"
  • then click apply and src folders will be created for you ..
  • 打开右侧的gradle侧边栏。
  • 点击设置
  • 将出现一个新对话框。
  • 在此对话框中,选中“自动为空内容根目录创建目录”选项
  • 然后单击应用,将为您创建 src 文件夹..

Images are attached for clarity.

为清楚起见,附上了图片。

Open the gradle sidebar on the right hand side.

打开右侧的 gradle 侧边栏。

Check the option "create directories for empty contents roots automatically"

选中“自动为空内容根目录创建目录”选项

回答by Richard Shin

If enabling the "Create directories for empty content roots automatically" setting does not show the src directory, check the project structure and try creating and deleting a dummy module.

如果启用“自动为空内容根目录创建目录”设置未显示 src 目录,请检查项目结构并尝试创建和删除虚拟模块。

  1. File -> Project Structure -> Modules -> Project Name -> Confirm that src is part of the hierarchy and exit out of the pop up
  2. Right click on the root folder of the project -> New -> Module
  3. The IDE may have refreshed, along with the visibility of the src folder
  1. 文件 -> 项目结构 -> 模块 -> 项目名称 -> 确认 src 是层次结构的一部分并退出弹出窗口
  2. 项目根文件夹右键->新建->模块
  3. IDE 可能已刷新,并且 src 文件夹的可见性

回答by justAnotherGuy

None of the above worked for me. Finally, had to go raw.

以上都不适合我。最后,不得不生吃。

gradle init --type java-library

Followed Mkyong's page on gradle init

其次Mkyong对gradle这个初始化页面

Then, simply 'Open' project in Intellij. Then updated project settings related to JAVA_HOME and Gradle home (Chances are these were related to my specific installation).

然后,只需在 Intellij 中“打开”项目。然后更新了与 JAVA_HOME 和 Gradle home 相关的项目设置(这些可能与我的特定安装有关)。

回答by sososocke

Add a directory named 'src'. Right click on it and then click Mark Directory as Sources Root.

添加名为“src”的目录。右键单击它,然后单击将目录标记为源根。

回答by ASB

Just right create on your project directory and choose New -> Directory -> (choose all four to be created: src/main/java, src/main/resource, src/test/java, and src/test/resource) -> enter

就在你的项目目录上创建,然后选择新建 -> 目录 ->(选择所有四个要创建的:src/main/java、src/main/resource、src/test/java 和 src/test/resource)->进入

right click on project directory

right click on project directory

choose the four choices

choose the four choices

found the answer here: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206806425-Source-Directories-Not-Being-Created-In-New-Project

在这里找到答案:https: //intellij-support.jetbrains.com/hc/en-us/community/posts/206806425-Source-Directories-Not-Being-Created-In-New-Project