IntelliJ IDEA 2019.3 Help

Maven projects

IntelliJ IDEA lets you manage Maven projects. You can link, ignore projects, synchronize changes in Maven and IntelliJ IDEA projects, and configure the build and run actions.

  1. In the Maven tool window, right-click a linked project.

  2. From the context menu, select Jump to Source F4.

    IntelliJ IDEA navigates to the appropriate Maven configuration file, and the related POM opens in the editor.

Ignore a Maven project

You can de-activate a Maven project using the Ignore Projects option. In this case, IntelliJ IDEA keeps the ignored Maven projects and subprojects in the Maven tool window, but stops their import (modules, content roots, goals, and so on) to the project. However, IntelliJ IDEA synchronizes the ignored projects with the current one. It might be helpful if you need to skip an irrelevant subproject.

  1. In the Maven tool window, right-click the project that you want to ignore.

  2. From the context menu, select Ignore Project.

  3. In the window that opens, click Yes if you want to remove the project from the Projects tool window.

If you want to activate your Maven projects or subprojects, select Unignore Projects from the context menu.

Re-import a Maven project

If you select the Import Maven projects automatically option in the Maven settings dialog, then IntelliJ IDEA will re-import the project automatically every time you make changes to the pom.xml file.

However, if you want to control the importing of your project, you can manually trigger the action.

  1. In the Maven tool window, right-click a linked project.

  2. From the context menu, select Reimport the Reimport icon.

    On invoking this action, IntelliJ IDEA parses the project structure in the Maven tool window.

    IntelliJ IDEA cannot re-import just a part of your project, it re-imports the whole project including subprojects and dependencies.

    If you configure a dependency through the Project Structure dialog (click the Project Structure button, from the main menu), the dependency will only appear in the IntelliJ IDEA Project tool window, not in the Maven tool window. Note that the next time you re-import your project, IntelliJ IDEA will remove the added dependency since IntelliJ IDEA considers the Maven configuration as a single source of truth.

You can have multiple Maven projects inside one IntelliJ IDEA project. It might be helpful if you keep parts of code in different projects or have some legacy projects on which you need to work. You can link such projects in IntelliJ IDEA and manage them simultaneously. You can also quickly remove such projects from the Maven structure.

  1. Open the Maven tool window.

  2. In the Maven tool window, click the Link Maven Projects icon to attach a Maven project.

  3. In the dialog that opens, select the desired pom.xml file, and click OK.

    The project is linked. The Maven tool window shows the toolbar and a tree view of Maven entities.

When you unlink a Maven project, IntelliJ IDEA removes all relevant projects and content roots, removes the Maven project from both the Maven tool window and the Project tool window, and stops its synchronization. It might be helpful if you need to fully remove the previously linked Maven project from the current IntelliJ IDEA project.

  1. In the Maven tool window, right-click a linked project.

  2. From the context menu, select Unlink Maven Projects (Delete ). Alternatively, you can select the linked project and click the Remove icon on the tool window's toolbar.

  3. Click OK.

Delegate build and run actions to Maven

By default, IntelliJ IDEA uses the native IntelliJ IDEA builder to build a Maven project. It might be helpful if you have a pure Java or a Kotlin project since IntelliJ IDEA supports the incremental build which significantly speeds up the building process. However, if you have a configuration that changes the compilation on the fly, or your build generates an artifact with a custom layout, then Maven would be preferable for the building process.

Build a project with Maven

  1. Click Maven settings in the Maven tool window. Alternatively, from the main menu select File | Settings/Preferences | Build, Execution, Deployment |Build Tools | Maven.

  2. Click Maven and from the list, select Runner.

  3. On the Runner page, select Delegate IDE build/run actions to maven.

    Maven Settings / Runner page

  4. Click OK.

  5. From the main menu, select Build | Build Project Ctrl+F9. IntelliJ IDEA invokes the appropriate Maven goals.

  6. Click the Build icon on the status bar to view the results of the sync in the Build tool window.

    Build tool window

Run and debug with Maven

When the Delegate IDE build/run actions to maven is selected, IntelliJ IDEA runs and debugs your code using Maven. HotSwap is also gets triggered, and the classes are reloaded during a debugging process.

You can use regular run and debug actions as you would in any other projects.

  1. Depending on what action you want to use, from the main menu, select Run | Run or Run | Debug.

  2. Check the results in the Run tool window or in the Debug tool window if you are debugging your code. For example, when you run the main method Ctrl+Shift+F10 in your Java project, IntelliJ IDEA uses Maven to run the class.

    Run tool window

Last modified: 24 December 2019