IntelliJ IDEA 2022.1 Help

Libraries

A library is a collection of compiled code that you can add to your project. In IntelliJ IDEA, libraries can be defined at three levels: global (available for many projects), project (available for all modules within a project), and module (available for one module).

A Java library can include class files, archives and directories with class files as well as directories with native libraries .dll, .so, or .jnilib.

Define a library

After you define a library and add it to module dependencies, the IDE will be supplying its contents to you as you write your code. IntelliJ IDEA will also use the code from the libraries to build and deploy your application.

Define a global library

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S.

  2. Under Platform Settings, select Global Libraries.

  3. Click the Add button and select one of the following:

    Defining a global library

References to global libraries are stored in the IDE configuration directory in options | applicationLibraries.xml.

Define a project library

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S.

  2. Under Project Settings, select Libraries.

  3. Click the Add button and select one of the following:

    Defining a project library

References to project libraries are stored together with the project in the .idea folder in libraries.

Add a library to module dependencies

Global and project libraries are not available until you add them to module dependencies.

  1. From the main menu, select File | Project Structure | Project Settings | Modules.

  2. Select the module for which you want to add a library and click Dependencies.

  3. Click the Add button and select Library.

    Adding a new module library
  4. In the dialog that opens, select a project or a global library that you want to add to the module.

    Alternatively, click New Library and select how do you want to add a new library: you can add a Java and Kotlin libraries from files on your computer, or download a library from Maven.

    Adding a new module library

References to module libraries are stored in the module .iml file. This file is used for keeping module configuration. For more information on module files, refer to Modules.

Download a library from Maven

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Libraries.

  2. Click Add and select From Maven.

  3. In the next dialog, specify the library artifact (for example, org.jetbrains:annotations:16.0.2). If you don't know its exact name, enter the key words and click Search.

    You can also specify another library location, and select whether you want to download transitive dependencies, source files, Javadoc files, or annotations.

    Downloading a library from Maven

IntelliJ IDEA will download the library from Maven or Nexus public repositories. You can also configure a custom remote repository.

Include specific transitive dependencies

If you want to include only specific transitive dependencies, you can use the library properties editor.

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S, and go to Modules | Dependencies.

  2. Select the necessary Maven library and click Edit.

  3. In the next dialog, click Edit, and then click Configure next to the Include transitive dependencies option.

  4. Select the dependencies you want to include in the library and click OK.

Change the library level

Move a library to a higher level

In IntelliJ IDEA, you can move a project or a module library to a higher level. This is helpful if you want to extend its scope of usage. For example, use this procedure if you want to use a module library across the project or the entire IDE.

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and locate the library that you want to change.

  2. Right-click the necessary library and select Move to Project Libraries or Move to Global Libraries.

    Moving a module library to a higher level

Copy a library to a lower level

You can create a copy of a library on a lower level. For example, use this procedure if you want to add more classes to a project library, but you want to use them in one module only.

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and locate the library that you want to change.

  2. Right-click the necessary library and select Copy to Project Libraries or Add to Modules.

    Copying a global library to a lower level

Exclude library items

IntelliJ IDEA allows you to temporarily exclude library items in order to increase IDE performance. You can exclude folders, archives (for example, JARs) and folders within archives.

Classes from excluded packages won't be shown in code completion suggestion lists, references to such classes will be shown in the editor as unresolved, and so on. However, when you compile or run your code, a library will still be used as a whole, irrespective of whether there are excluded items in that library or not.

Exclude items from a project or a global library

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Libraries.

  2. Click Exclude and select the library items that you want to exclude.

Exclude items from a module library

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and go to Modules | Dependencies.

  2. Click Exclude and select the library items that you want to exclude.

Excluded items will be marked with the Excluded root icon. To return library items to their original state, remove the excluded items.

Configure a custom remote repository

You can view the full list of remote repositories and add a custom repository in the settings. Note that IntelliJ IDEA can load libraries from Maven even if you don't use Maven as a build tool for your project.

  1. In the Settings/Preferences dialog Ctrl+Alt+S, go to Build, Execution, Deployment | Remote Jar Repositories.

  2. Click Add in the corresponding dialog section, and specify the repository URL.

    Configuring custom remote repository

Configure library documentation

You can add library documentation to IntelliJ IDEA so that you can get information about symbols and method signatures right from the editor in the Quick Documentation popup.

You can also configure external documentation by specifying the path to the reference information online. External documentation opens the necessary information in a browser so that you can navigate to related symbols and keep the information for further reference at the same time.

Specify library documentation paths

To view external library documentation, configure the documentation URL first.

  1. In the Project Structure dialog Ctrl+Alt+Shift+S, select Libraries.

  2. Select the necessary library, click the Specify Documentation URL icon and enter the external documentation URL.

    Specifying library documentation path
  3. Apply the changes and close the dialog.

Add library documentation to your project

You can add downloaded documentation to your project to be able to access it offline.

  1. From the main menu, select File | Project Structure Ctrl+Alt+Shift+S and click Libraries.

  2. Select the library for which you want to add the documentation and click the Add button in the right section of the dialog.

    Adding library documentation
  3. In the dialog that opens, select the file with the documentation and click Open.

  4. Apply the changes and close the dialog.

When the documentation is configured, you can open it in the editor.

Last modified: 10 August 2022