IntelliJ IDEA 13:新的 Scala SBT 项目没有生成 src 目录结构

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

IntelliJ IDEA 13: new Scala SBT project hasn't src directory structure generated

scalaintellij-ideasbtintellij-13

提问by aleung

I followed the getting start video on Jetbrains website to setup IntelliJ IDEA 13.1 Community Edition to work with Scala. Scala plugin v0.36.431 had been installed. While I created a new Scala SBT project with wizard, there was no src/directory structure generated in the project. Only two sbt files were generated:

我按照 Jetbrains 网站上的入门视频来设置 IntelliJ IDEA 13.1 社区版以与 Scala 一起使用。Scala 插件 v0.36.431 已安装。当我使用向导创建了一个新的 Scala SBT 项目时,项目中没有src/生成目录结构。只生成了两个 sbt 文件:

scala-course/
├── build.sbt
└── project
    └── plugins.sbt

From the video and other document I know that there should be a src/directory structure, including src/main/scala, src/test/scala, etc. sbt uses the same directory structure as Maven for source files by default.

从视频和其他文件,我知道,应该有一个src/目录结构,其中src/main/scalasrc/test/scala等SBT默认使用相同的目录结构Maven的源文件。

I can create those folders manually and mark it as source root. However it is trivial. So my question is: Why IntelliJ IDEA new project wizard doesn't generate the directory structure as said in document? Was I doing something wrong? I checked the preferences and couldn't find anything that seems related.

我可以手动创建这些文件夹并将其标记为源根。然而,这是微不足道的。所以我的问题是:为什么 IntelliJ IDEA 新项目向导没有生成文档中所说的目录结构?我做错了什么吗?我检查了首选项,但找不到任何似乎相关的内容。

采纳答案by aleung

Thanks to lpiepiora, with his hintI find out the reason.

感谢 lpiepiora,在他的暗示下我找到了原因。

Because my sbt is newly installed, there is nothing in ~/.ivy2/cache/and ~/.sbt/boot/. sbt needed to download required dependencies from repositories on network. It happened that my proxy to internet had something wrong, download stuck.

因为我的sbt是新装的,~/.ivy2/cache/and里面什么都没有~/.sbt/boot/。sbt 需要从网络上的存储库下载所需的依赖项。碰巧我的互联网代理出了点问题,下载卡住了。

And also need to notice that, if quit IntelliJ IDEA when sbt is running in background, the next time you'll get error of waiting for some lock file. Have to remove the lock file on filesystem and restart IntelliJ IDEA again.

还需要注意的是,如果在后台运行sbt时退出IntelliJ IDEA,下次你会得到等待某个锁定文件的错误。必须删除文件系统上的锁定文件并再次重新启动 IntelliJ IDEA。

After fixed the network problem, everything work as promised. It requires several minutes, depends on network speed, to download required jar files. After finished, the src/directory structure is created.

修复网络问题后,一切都按承诺进行。下载所需的 jar 文件需要几分钟,具体取决于网络速度。完成后,src/创建目录结构。

回答by lpiepiora

Normally it should create these folders automatically. It may take a while though - it takes couple of seconds in my case.

通常它应该自动创建这些文件夹。不过可能需要一段时间 - 在我的情况下需要几秒钟。

When creating project make sure you have selected Scala -> SBT, then proceed with the wizard.

创建项目时,请确保您已选择Scala -> SBT,然后继续向导。

Once the Finishis clicked, the project will be loaded. This part takes couple of seconds, and I can see no src/main/scalanor src/test/scalagenerated until it's done. Observe the bottom of the screen to see when it's done.

一旦完成点击,该项目将被加载。这部分需要几秒钟,在完成之前我看不到src/main/scala也没有src/test/scala生成。观察屏幕底部以查看何时完成。

Loading Process

加载过程

Once the process is finished, you'll see the folders.

该过程完成后,您将看到文件夹。

Loaded Done

加载完成

If that's not the case, check the settings. You should have the Create directories for empty content roots automaticallychecked. You may want to check Use auto-importto automatically propagate changes in the build.sbt.

如果不是这种情况,请检查设置。您应该自动检查为空内容根创建目录。您可能需要选中使用自动导入自动传播build.sbt.

Settings

设置

After changing the settings (if the change is required) you may need to refresh the project, as seen in picture below.

更改设置后(如果需要更改),您可能需要刷新项目,如下图所示。

Refresh Settings

刷新设置

回答by Zaptree

This can also happen if you do not have a JDK selected. For some reason you no longer get the option to select an SDK so you must make sure you have configured this before hand. To fix this do the following:

如果您没有选择 JDK,也会发生这种情况。出于某种原因,您不再有选择 SDK 的选项,因此您必须确保事先进行了配置。要解决此问题,请执行以下操作:

From the welcome screen, go to 
Configure -> Project defaults -> Project structure and add the jdk.

Source: What's the reason for "Error:Cannot determine Java VM executable in selected JDK"?

来源: “错误:无法确定所选 JDK 中的 Java VM 可执行文件”的原因是什么?

回答by Jo?o Amaral

I followed the instructions in this thread but I had a java crash in the final phase in sbt with the configuration bellow and I think this info maybe useful:

我按照此线程中的说明进行操作,但在 sbt 的最后阶段我遇到了 java 崩溃,配置如下,我认为此信息可能有用:

The problem happened with IDEA 2016.2, sbt 0.13.8 (I tried later to import using 0.13.12 but the crash was the same), scala 2.11.8 and ubuntu 16.04.

问题发生在 IDEA 2016.2、sbt 0.13.8(我后来尝试使用 0.13.12 导入但崩溃是一样的)、scala 2.11.8 和 ubuntu 16.04。

The only way I could make it work was to use java 8 instead of 9.

我可以让它工作的唯一方法是使用 java 8 而不是 9。

error: error while loading package, Missing dependency 'object java.lang.Object in compiler mirror', required by /home/jbamaral/.sbt/boot   at xsbt.boot.Boot.main(Boot.scala)
... 
stack log here
...
[error] scala.reflect.internal.MissingRequirementError: object java.lang.Object in compiler mirror not found.