Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When would I use the "Mark directory as ..." option in IntelliJ IDEA?

I am a newcomer finding my way around the IntelliJ IDE, for which I am currently using for coding in Scala.

Right clicking in the Project window brings up a pop-up, with "Mark Directory As ..." as an option, with the following choices:

  • Sources Root
  • Test Sources Root
  • Resources Root
  • Test Resources Root
  • Excluded
  • Generated Sources Root

Can I know would I use the "Mark Directory As ..." option? And also what would each of the choices do? I have tried looking around, but so far most websites have been rather vague with their explanations.

Thanks for your help.

like image 287
beginner Avatar asked Aug 31 '16 16:08

beginner


People also ask

What does marking directory as sources root do?

In Pycharm, if you right click in a folder inside your project, you can mark it as sources root , so then you can import modules from this folder and subfolders.

What is directory in IntelliJ?

Configuration directory The IntelliJ IDEA configuration directory contains user-defined IDE settings, such as keymaps, color schemes, custom VM options, platform properties, and so on. Windows. macOS.

How do I mark a folder as a module in IntelliJ?

From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Modules. Select the necessary module and open the Sources tab. to the right of the necessary folder (folder path). Specify the path relative to the output folder root, and click OK.


1 Answers

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.

like image 173
Mikesname Avatar answered Sep 30 '22 17:09

Mikesname