IntelliJ IDEA 2016.3 Help

Configuring Content Roots

On this page:

Introduction

When created, a module, normally, has one content root.

You can create additional content roots as well as remove the unnecessary ones.

Adding a content root

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane, select Modules.
  3. In the pane to the right, select the necessary module.
  4. In the right-hand part of the dialog, select the Sources tab.
  5. Click Add Content Root.
    /help/img/idea/2016.3/add-content-root.png
  6. In the dialog that opens, select the folder to be added as a content root, and click OK.
  7. Click OK in the Project Structure dialog.

Specifying folder categories: sources, tests, etc.

Folders within content roots can be assigned to the following categories: sources, test sources, generated sources, generated test sources and excluded folders (in Java modules - also resources and test resources). This can be done in the Project tool window or in the Project Structure dialog.

Specifying folder categories in the Project tool window

Most of the functions for working with folder categories in the Project tool window (View | Tool Windows | Project) are accessed through Mark Directory as | <Option> in the context menu. The <Option>, in most of the cases, is the name of the category that you want to assign to the selected folder.

By using this UI, you can:

  • Assign a folder to a category or change the folder category: Mark Directory as | <Category>, e.g. Mark Directory as | Test Sources Root.
    /help/img/idea/2016.3/mark-as-tests-project-tool-window.png
  • Cancel the folder association with its current category: Mark Directory as | Unmark as <Category>, e.g. Unmark as Test Sources Root. As a result, a folder becomes and "ordinary" folder (/help/img/idea/2016.3/folder.png).
    /help/img/idea/2016.3/mark-as-smth-else-project-tool-window.png

    For folders that you have made excluded by means of the Mark Directory as | Excluded command, to restore the previous category or to make a folder an ordinary one, use Mark Directory as | Cancel Exclusion.

  • Assign a subfolder to a different category (Mark Directory as | <Category>). By using this feature, you can, for example, make a folder within a source root folder excluded or mark a folder within an excluded folder as containing generated sources.
  • Create a content root: for a subfolder that inherited its excluded status from its "parent" folder, use the Mark Directory as | Not Excluded command.

Hiding and showing excluded folders. To hide or show your excluded folders, click /help/img/idea/2016.3/viewMode.png on the title bar and then click Show Excluded Files.

Specifying folder categories in the Project Structure dialog

The UI for working with folder categories is on the Sources tab. To get to this tab, open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S), select Modules, select the necessary module, and then select Sources in the right-hand part of the dialog.

By using the Sources tab, you can:

  • Assign a folder to a category or change the folder category: select the category (e.g. Tests) to the right of Mark as or from the context menu in the left-hand pane.
    /help/img/idea/2016.3/mark-as-tests-project-structure.png
  • Cancel the folder association with its current category. Do one of the following:
    • Click the current category to the right of Mark as (e.g. Tests if the folder is currently assigned to test sources).
    • Click the current category in the context menu.
    • In the right-hand pane, under the category name (e.g. Test Source Folders), click /help/img/idea/2016.3/remove-x-icon.png to the right of the folder name (or folder path).
    /help/img/idea/2016.3/mark-as-smth-else-project-structure.png
  • Specify that the folder contents (sources or resources) are generated. For a folder already assigned to sources, resources, test sources or test resources, in the right-hand pane, under the category name (e.g. Test Source Folders), click /help/img/idea/2016.3/rootPrefix.gif to the right of the necessary folder (folder path).
    /help/img/idea/2016.3/assign-package-prefix.png

    Then select For generated sources or For generated resources in the dialog that opens.

  • Assign a subfolder to a different category. By using this feature, you can, for example, make a folder within a source root folder excluded or mark a folder within an excluded folder as containing generated sources. The procedure - for the subfolder of interest - is the same as for changing the folder category.

Assigning a package prefix to a folder with Java sources

In Java modules, you can assign a package prefix to a folder containing source files (e.g. com.mycompany.myapp). This eliminates the necessity to create the corresponding folder structure in that folder (e.g. com/mycompany/myapp). For more information, see Package prefix for Java source roots.

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane, select Modules.
  3. In the pane to the right, select the necessary module.
  4. In the right-hand part of the dialog, select the Sources tab.
  5. In the right-hand pane, under Source Folders or Test Source Folders, click /help/img/idea/2016.3/rootPrefix.gif to the right of the necessary folder (folder path).
    /help/img/idea/2016.3/assign-package-prefix.png
  6. In the dialog that opens, specify the package prefix and click OK.
  7. Click OK in the Project Structure dialog.

Specifying the output path for resources

During the build process, by default, the resources are copied into the root of the compilation output folder. If necessary, you can specify a different folder within that output folder.

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane, select Modules.
  3. In the pane to the right, select the necessary module.
  4. In the right-hand part of the dialog, select the Sources tab.
  5. In the right-hand pane, under Resource Folders or Test Resource Folders, click /help/img/idea/2016.3/rootPrefix.gif to the right of the necessary folder (folder path).
    /help/img/idea/2016.3/resource-properties-project-structure.png
  6. In the dialog that opens, specify the path relative to the output folder root, and click OK.
  7. Click OK in the Project Structure dialog.

Removing a content root

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane, select Modules.
  3. In the pane to the right, select the necessary module.
  4. In the right-hand part of the dialog, select the Sources tab.
  5. To the right of the content root that you want to remove, click /help/img/idea/2016.3/remove-x-icon.png.
    /help/img/idea/2016.3/remove-content-root.png
  6. Confirm you intention to remove the content root. (The corresponding folder won't be physically deleted.)
  7. Click OK in the Project Structure dialog.

See Also

Last modified: 29 November 2016