IntelliJ IDEA 14.1.0 Help

Configuring Content Roots

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

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

In this section:

Adding Content Roots

To add a content root, follow these steps

  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, on the Module page, select the Sources tab.
  5. Click Add Content Root.
    add-content-root
  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

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 Structure dialog or in the Project tool window.

In Java modules, the folders marked as containing source code can be assigned a package prefix.

See also, Sources Tab.

Here is how you assign a folder to test sources. In a similar way, you can assign a folder to any other category. The only exceptions are generated sources and generated test sources.

To specify folder categories in the project structure dialog, follow these steps

  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, on the Module page, select the Sources tab.
  5. Select the folder whose contents you want to assign to test sources and do one of the following:
    • To the right of Mark as, click Tests.
    • Select Tests in the context menu.
    mark-as-tests-project-structure
  6. Click OK in the Project Structure dialog.

In a similar way you can change the folder category at a later time. (Just select a different category for a folder.)

To cancel the folder association with its current category (i.e. to make a folder an "ordinary" folder), do one of the following:

  • Click the current category name to the right of Mark as (e.g. Tests if the folder is currently assigned to test sources).
  • Click the current category name in the context menu.
  • In the right-hand pane, under the category name (e.g. Test Source Folders), click remove-x-icon to the right of the folder path (folder name).
    mark-as-smth-else-project-structure

To specify that a source or test source folder contains generated sources, follow these steps

  1. In the right-hand pane, under Source Folders or Test Source Folders, click rootPrefix to the right of the necessary folder (folder path).
    assign-package-prefix
  2. In the dialog that opens, select For generated sources and click OK.

To assign a category to a folder in the Project tool window, follow these steps

  1. Open the Project tool window (e.g. View | Tool Windows | Project).
  2. Select the folder that you want to assign to a certain category.
  3. In the context menu, point to Mark Directory As and select the desired category.
    mark-as-tests-project-tool-window

In a similar way you can change the folder category at a later time. (Just select a different category from the context menu.)

To cancel the folder association with its current category (i.e. to make a folder an "ordinary" folder folder), select Unmark as <current_category> Root (e.g. Unmark as Test Sources Root).

mark-as-smth-else-project-tool-window

Assigning a Package Prefix to a Folder Containing 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.

To assign a package prefix to a java source folder, follow these steps

  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, on the Module page, select the Sources tab.
  5. In the right-hand pane, under Source Folders or Test Source Folders, click rootPrefix to the right of the necessary folder (folder path).
    assign-package-prefix
  6. In the dialog that opens, specify the package prefix and click OK.
  7. Click OK in the Project Structure dialog.

Removing content roots

To remove a content root, follow these steps

  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, on the Module page, select the Sources tab.
  5. To the right of the content root that you want to remove, click remove-x-icon.
    remove-content-root
  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: 14 July 2015