IntelliJ IDEA 2016.3 Help

Configuring Module Dependencies and Libraries

On this page:

See also, Dependencies, Library and Configuring Project and Global Libraries.

Creating a module library and adding it to module dependencies

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click /help/img/idea/2016.3/new.png and select Jars or directories.
  6. In the dialog that opens, select the necessary files and folders. These may be individual .class and .java files, directories and archives (.jar and .zip) containing such files as well as directories with Java native libraries (.dll, .so or .jnilib). Click OK.
  7. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

See also, Adding existing libraries to module dependencies and Adding a project or global library to module dependencies.

Adding existing libraries to module dependencies

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click /help/img/idea/2016.3/new.png and select Library.
  6. In the Choose Libraries dialog, select one or more libraries and click Add Selected.

    The libraries you can choose from include:

    • Global libraries
    • Project libraries existing in the current project
    • Application server libraries for the servers registered in IntelliJ IDEA
  7. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

See also, Adding a project or global library to module dependencies.

Creating a module, project or global library and adding it to module dependencies

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click /help/img/idea/2016.3/new.png and select Library.
  6. In the Choose Libraries dialog, click New Library.
  7. If suggested, select:
    • Java to create a Java library. Select the files and folders to be included in the library in the dialog that opens.
    • From Maven to download a Java library from a public Maven repository. Specify the artifact to be downloaded and the associated settings in the Download Library from Maven Repository dialog.
  8. In the Configure Library dialog:
    1. Specify the library name.
    2. Select the library level (global, project or module).
    3. Configure the library contents using /help/img/idea/2016.3/new.png, /help/img/idea/2016.3/iconLibExclude.png and /help/img/idea/2016.3/delete.png.
    4. Click OK.
  9. In the Choose Libraries dialog, click Add Selected.
  10. If necessary, select the Export option and change the dependency scope.
  11. Click OK in the Project Structure dialog.

See also, Creating a project or a global library and Adding a project or global library to module dependencies.

Creating a library in the Project tool window

Sometimes, you don't need to open the Project Structure dialog to create a library and add it to dependencies of a module. This is the case when there are .jar files within your project content roots.

You can select such .jar files in the Project tool window and use these files to create a library. When doing so, you will be able to select the library level and the module to whose dependencies the new library should be added.

In a similar way, you can use a directory containing .jar files to create a library.

  1. Open the Project tool window (e.g. View | Tool Windows | Project).
  2. Select the .jar file or files to be included in the library, or a directory that contains the .jar files of interest.
  3. Select Add as Library from the context menu.
  4. In the Create Library dialog, specify the library name, level and the module in which this library will be used.

Adding dependencies on modules

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, click /help/img/idea/2016.3/new.png and select Module Dependency.
  6. In the Choose Modules dialog, select one or more modules the current module should depend on, and click OK. (Your selection is limited to the modules of the current project. That is, you cannot select the modules from a different project.)
  7. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.

Changing the order of dependencies

In certain cases, the order of module dependencies may be important, see Order of dependencies.

To reorder the items, use /help/img/idea/2016.3/arrowUp.png and /help/img/idea/2016.3/arrowDown.png. Clicking these icons moves the selected item one line up or down in the list.

Sorting the list of dependencies

You can sort the dependencies by their names and scopes by clicking the cells in the header row.

If you click a cell once, the list is sorted by the corresponding column in the ascending order. The sorting marker appears in the cell: /help/img/idea/2016.3/sortMarkerAsc.png. When you click the cell for the second time, the information is sorted in the descending order. To show this, the sorting marker changes its appearance: /help/img/idea/2016.3/sortMarkerDesc.png. Finally, when you click the cell for the third time, the initial unsorted state is resorted.

Note that the sorting operations don't change the actual order of dependencies.

When the list is sorted, the icons for changing the order of dependencies are inactive.

Configuring the library contents

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, select the library of interest, and click /help/img/idea/2016.3/editFlexLibraryNew.png.
  6. In the Configure Library dialog that opens, use /help/img/idea/2016.3/new.png, /help/img/idea/2016.3/iconLibExclude.png and /help/img/idea/2016.3/delete.png to manage the library contents.
  7. Click OK in the Project Structure dialog.

Moving a module library to the project or global level

  1. Open the Project Structure dialog (e.g. Ctrl+Shift+Alt+S).
  2. In the left-hand pane of the dialog, select Modules.
  3. In the pane to the right, select the module of interest.
  4. In the right-hand part of the dialog, on the Module page, select the Dependencies tab.
  5. On the Dependencies tab, right-click the library of interest, and select Move to Project Libraries or Move to Global Libraries.
  6. In the Move Library dialog, if necessary, edit the library name. If you want to change the location of the library files, select the Move library files to check box and specify the corresponding location.

Note that the corresponding library is not removed from the list of the module dependencies.

Downloading missing library sources from the Maven repository

For the library files originating form the Maven public repository, when missing sources are detected, IntelliJ IDEA suggests downloading and including those sources in the library.

To access these features, IntelliJ IDEA provides the corresponding hyperlinks in the editor.

/help/img/idea/2016.3/download_from_sonatype.png

See Also

Last modified: 21 March 2017