IntelliJ IDEA 2016.1 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.

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

    Using the Project Structure dialog

    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. Select the folder of interest and do one of the following:
      • To the right of Mark as, click the name of the category, e.g. Tests.
      • Select the category (e.g. Tests) from 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: 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 name (or folder path).
      mark-as-smth-else-project-structure

    Specifying that the sources or resources are generated

    To specify that a folder contains generated sources or resources, you should first assign that folder to sources, resources, test sources or test resources, and then do the following:
    1. In the right-hand pane, under Source Folders, Resource Folders, Test Source Folders or Test Resource 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 or For generated resources and click OK.

    Using the Project tool window

    1. Open the Project tool window (e.g. View | Tool Windows | Project).
    2. Right-click the folder of interest, 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: 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 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 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.

    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 rootPrefix to the right of the necessary folder (folder path).
      resource-properties-project-structure
    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 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: 13 July 2016