Configuring Content Roots
On this page:
- Introduction
- Adding a content root
- Specifying folder categories: sources, tests, etc.
- Specifying folder categories in the Project tool window
- Specifying folder categories in the Project Structure dialog
- Assigning a package prefix to a folder with Java sources
- Specifying the output path for resources
- Removing a content root
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
- Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
- In the left-hand pane, select Modules.
- In the pane to the right, select the necessary module.
- In the right-hand part of the dialog, select the Sources tab.
- Click Add Content Root.
- In the dialog that opens, select the folder to be added as a content root, and click OK.
- 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
- Specifying folder categories 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 ( ) 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.
- 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 ().
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 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.
- Cancel the folder association with its current category. Do one of the following:
- 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 to the right of the necessary folder (folder path).
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.
- Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
- In the left-hand pane, select Modules.
- In the pane to the right, select the necessary module.
- In the right-hand part of the dialog, select the Sources tab.
- In the right-hand pane, under Source Folders or Test Source Folders, click to the right of the necessary folder (folder path).
- In the dialog that opens, specify the package prefix and click OK.
- 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.
- Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
- In the left-hand pane, select Modules.
- In the pane to the right, select the necessary module.
- In the right-hand part of the dialog, select the Sources tab.
- In the right-hand pane, under Resource Folders or Test Resource Folders, click to the right of the necessary folder (folder path).
- In the dialog that opens, specify the path relative to the output folder root, and click OK.
- Click OK in the Project Structure dialog.
Removing a content root
- Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
- In the left-hand pane, select Modules.
- In the pane to the right, select the necessary module.
- In the right-hand part of the dialog, select the Sources tab.
- To the right of the content root that you want to remove, click .
- Confirm you intention to remove the content root. (The corresponding folder won't be physically deleted.)
- Click OK in the Project Structure dialog.