IntelliJ IDEA 2019.2 Help

Modules

In IntelliJ IDEA, a module is an essential part of any project – it's created automatically together with a project. Projects can contain multiple modules – you can add new modules, group them, and unload the modules you don't need at the moment.

Modules consist of a content root and a module file. A content root is a folder where you store your code. Usually, it contains subfolders for source code, unit tests, resource files, and so on. A module file (the .iml file) is used for keeping module configuration, including content or source roots, dependencies, framework-specific settings in facets, and so on.

Projects with multiple modules

IntelliJ IDEA allows you to have many modules in one project, and they shouldn't be just Java. You can have one module for a Java application and another module for a Ruby on Rails application or for any other supported technology.

An application that consists of a client side and a server side is a good example a two-module project.

Add a new module to your project

  1. Right-click the top-level directory in the Project tool window and select New | Module. The New Module wizard opens.

  2. From the list on the left, select a module type.

  3. In the right-hand part of the dialog, select an SDK that you want to use from the Module SDK list. You can use the project SDK or specify a new one.

  4. In the Additional Libraries and Frameworks section, select additional assets that you want to use in this module.

  5. On the next step, name the module and specify the location of the content root and the .iml file. You can place them within or outside of the project.

  6. Click Finish.

Import an existing module to the project

You can import a module and add it your project, or you can use the project as a shared view for multiple individual modules. This is useful if you have several projects and your workflow requires that you switch between them.

To add an existing module to your project, import the .iml file:

  1. From the main menu, select File | New | Module from Existing Sources.

  2. In the dialog that opens, specify the path the .iml file of the module that you want to import, and click Open.

    On this stage, the module is not a part of the project.

  3. In the Project tool window, drag the imported module to the top-level directory to add it to the project.

Group modules

In IntelliJ IDEA, you can logically group modules. If you have a large project with multiple modules, grouping will make it easier to navigate through your project. To sort out modules, give them fully qualified names. For example, if you want to group all CDI modules, add the cdi prefix to their names.

  1. Open the Project Structure dialog (Ctrl+Shift+Alt+S) and click Modules.

  2. Select the modules you want to group, open the context menu, and click Change Module Names.

  3. Specify a prefix and apply the changes.

    To view all modules on the same level in the Project Structure dialog, use the Flatten Modules context menu option.

Convert module groups to qualified names

In earlier versions, IntelliJ IDEA used groups for joining modules together. If you've configured manual module groups, you will be able to continue working with them, but qualified names won't be available. To enable qualified names:

  1. From the main menu, select File | Convert Module Groups to Qualified Names.

  2. In the next dialog, review the new module names and adjust them if necessary.

  3. Apply the changes and close the dialog.

Last modified: 1 August 2019