IntelliJ IDEA 12.1.0 Web Help

This section discusses the main tasks related to managing module dependencies. Almost all of these tasks are initiated on the Dependencies Tab of the Module page (in the Project Structure dialog).

Many of the same features are available when working with project and global libraries, see Configuring Project and Global Libraries.

Creating a new module library and adding it to module dependencies
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, click add and select single_entry_library.png Jars or directories.
  3. In the dialog that opens, select the necessary files and folders. These may be individual .class, .java, .jar and .zip files, and the directories containing such files. Click OK.
  4. If necessary, select the Export option and change the dependency scope.
  5. Click OK in the Project Structure dialog.
Adding existing libraries to module dependencies
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, click add and select library.png Library.
  3. In the Choose Libraries dialog, select one or more libraries and click Add Selected.

    Note

    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.
  4. If necessary, select the Export option and change the dependency scope.
  5. Click OK in the Project Structure dialog.
Creating a new module, project or global library and adding it to module dependencies
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, click add and select library.png Library.
  3. In the Choose Libraries dialog, click New Library.
  4. If suggested, select:
    • Java to create a Java library. Select the files and folders containing the library resources 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.
  5. 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 add and delete.
    4. Click OK.
  6. In the Choose Libraries dialog, click Add Selected.
  7. If necessary, select the Export option and change the dependency scope.
  8. Click OK in the Project Structure dialog.
Creating a new library in the Project tool window

Sometimes, you don't need to open the Project Structure dialog to create a new library and add it to the 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 that should depend on the library that you are creating.

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

  1. Open the Project tool window.
  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 that should depend on this library.
Adding dependencies on modules
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, click add and select module_dependency.png Module Dependency.
  3. In the Choose Modules dialog, select one or more modules the current one should depend on, and click OK.

    Note

    Your selection is limited to the modules of the current project. That is, you cannot select the modules from a different project.

  4. If necessary, select the Export option and change the dependency scope.
  5. Click OK in the Project Structure dialog.
Changing the order of dependencies

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

To reorder the items, use arrowUp and arrowDown. Clicking these icons moves the selected item one line up or down in the list.

Configuring the library contents
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, select the library whose contents you want to configure, and click edit1.
  3. Use add and delete to manage the library contents. For more information, see Configure Library Dialog and Project Library and Global Library Pages.
  4. Click OK in the Project Structure dialog.
11.0+
Moving a module library to the project or global level
  1. Open the module settings and select the Dependencies tab.
  2. On the Dependencies tab, right-click the library of interest, and select Move to Project Libraries or Move to Global Libraries.
  3. 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.



Tip

If while exploring code you've encountered a class with the missing sources, it is not a problem. With IntelliJ IDEA, you can attach sources "on the fly": having detected missing sources, IntelliJ IDEA displays a banner, and suggests to download the missing sources from oss.sonatype.org, and attach them to your libraries.

download_from_sonatype

See Also

Concepts:

Procedures:

Reference:

Web Resources: