IntelliJ IDEA 13.1 Web Help

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

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

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.

Adding a content root
  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCommand SemicolonCommand SemicolonCommand Semicolon).
  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 in the Project Structure dialog

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.

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCommand SemicolonCommand SemicolonCommand Semicolon).
  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:

  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.
Specifying folder categories in the Project tool window

Here is how you assign a folder to test sources. In a similar way, you can assign a folder to any other category.

  1. Open the Project tool window (e.g. View | Tool Windows | Project).
  2. Select the folder that you want to assign to test sources. (Note that the excluded folders are not shown in the tool window.)
  3. In the context menu, point to Mark Directory As and select Test Sources Root.

    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), 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.

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCommand SemicolonCommand SemicolonCommand Semicolon).
  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 a content root
  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCtrl+Shift+Alt+SCommand SemicolonCommand SemicolonCommand Semicolon).
  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

Concepts:

Reference:

Web Resources: