IntelliJ IDEA 2018.1 Help

Keymap:

Working with libraries

A library is a collection of compiled code that a module can depend on. 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 Java 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.

In IntelliJ IDEA, libraries can be defined in the Project Structure dialog. Go to File | Project Structure, or press Ctrl+Shift+Alt+S.

You can also create a new library from JAR files located within a project content root. Select these files in the Project tool window, and then select Add as Library from the context menu.

To define a global library, select Global Libraries under the Platform Settings section.

To define a project library, select Libraries under the Project Settings section.

Click , select a library type (Java or Kotlin/JS), and then select files on the disk from which you want to create a library.

To define a module library:

Select Modules under the Project Settings section.

Open the Dependencies tab.

Click and select Library.

Click New Library at the bottom of the dialog.

You can create a new library from files on your computer, or download a library from a repository.

Add a library to module dependencies

Global and project libraries are not available until you add them to module dependecies:

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

Open the Dependencies tab and click .

Select a library you want to add and click Add Selected at the bottom of the dialog.

Download libraries from Maven

When you select to add library from Maven (| from Maven), IntelliJ IDEA will download a library from Maven or Nexus public repositories. You can also configure the custom remote repository.

In the Download from Maven Repository dialog, specify a name of the library that you want to download, choose where you want to save it to. You can also specify whether you want to download transitive dependencies, source and JavaDoc files.

Exclude library items

IntelliJ IDEA allows you to temporarily exclude library items in order to increase IDE performance. You can exclude folders, archives (e.g. 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, etc. 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.

To exclude items from a project or a global library, click in the right-hand part of the Project Structure dialog, and select the items you want to exclude.

To exclude items from a module library, select the library and click . Then click and select items you want to exclude. Excluded items will be marked with the icon.

To return library items to their original state, remove the excluded items.

Change library 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, if you want to use a module library across the project or the entire IDE. To move a library to a higher level, right-click this library in the Project Structure dialog, and select Move to Project Libraries or Move to Global Libraries.

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

Right-click the necessary global library and select Copy to Project Libraries. Then specify if you also want a copy of the library files and where that copy should be created. For a global or project library included in the dependencies of a module, to start creating a copy at the module level, right-click the required library and select Copy to Module Libraries.