我何时使用" Mark目录作为..." IntelliJ IDEA中的选项?

时间:2016-08-31 16:01:08

标签: scala intellij-idea

我是一名新手,围绕IntelliJ IDE找到了解决方案,我目前正在使用它来进行Scala编码。

在“项目”窗口中单击鼠标右键会弹出一个弹出窗口,其中包含" Mark Directory As ..."作为一种选择,有以下选择:

  • Sources Root
  • 测试来源根
  • 资源根
  • 测试资源根
  • 排除
  • Generated Sources Root

我可以知道我会使用" Mark Directory As ..."选项?还有每个选择会做什么?我试过环顾四周,但到目前为止,大多数网站的解释都比较模糊。

感谢您的帮助。

1 个答案:

答案 0 :(得分:12)

Lets go through the options:

  • Sources Root - this is where your actual project code goes - typically in src/main/scala (though you can change that, or add extra source directories in your build). Directories nested below this level should be packages. Intellij needs to know these are sources so it can highlight them, check them for errors, etc.
  • Test Sources Root - likewise, this is where your test sources live, and will often mirror the package structure of your main sources.
  • Resources Root - where non-compiled files (such as i18n messages or configuration) live, which need to be deployed with the final artifact (jar or war or whatever).
  • Test Resources Root - non-compiled files used by tests, such as .sql fixtures, etc.
  • Excluded - anything you don't want Intellij to index or care about at all. If you have a directory tree (e.g. a database) in your project root which isn't part of your code base you should mark it as Excluded, since this will prevent Intellij indexing the files. Not only can indexing take a long time on large projects, having a lot of non-project files indexed by the IDE will slow down the frequently-used Go to Class/File/Symbol operations, and cause them to offer irrelevant suggestions.
  • Generated Sources Root - sources that are managed by a build tool or some other process. For example, the Play Framework (2.x) generates Scala code from HTML and routing info automatically when the project is built. It's important that generated sources are marked as such (as opposed to normal code, or non-code) so that the IDE can resolve references to it (ensuring code validity) whilst being aware that you shouldn't edit it yourself. This will also prevent generated code being offered as suggestions in the Go to Class/File/Symbol dialogs.

If you're using SBT you might not have to use "Mark directory as..." manually much at all, since the Intellij SBT plugin has grown smarter about inferring source, resources, and generated source directories automatically from the build.sbt file.

It's worth noting that Intellij plugins can add additional options to the "Mark directory as..." menu - for example, the Python plugin has a "Template Folder" option.