IntelliJ IDEA 2017.1 Help

Getting Started with Maven

IntelliJ IDEA lets you work with Maven by importing a project that contains pom.xml or by creating a Maven project from scratch.

Creating Maven Project

  1. Open Project Wizard, in the left-hand pane select Maven.
  2. In the right-hand pane, specify the following options:
    • Project SDK - specify your project SDK (JDK).
      If the necessary JDK is already defined in IntelliJ IDEA, select it from the list. Otherwise, click New and select the installation folder of the desired JDK.
    • If you want to create a Maven project based on one of the Maven Archetypes, select the Create from archetype check box, and select the desired archetype from the list.
      You can click Add Archetype and add a new archetype to the list of the existing ones.
    Click Next.
  3. On the next page of the wizard, specify properties for your Maven project and click Next.
  4. On the next page of the wizard, specify project's information and click Finish.

    IntelliJ IDEA creates a project with pom.xml.

Importing Project from the Maven Model

IntelliJ IDEA enables you to create a project on the base of an existing Maven project, represented by pom.xml.

  1. If no project is currently open in IntelliJ IDEA, click Import Project on the Welcome screen. Otherwise, select File | New | Project from Existing Sources.
  2. In the dialog that opens, select the directory that contains the project to be imported, or a file that contains an appropriate project description. Click OK.
  3. On the first page of the Import Project wizard, select Maven, and click Next. (This page is not shown if IntelliJ IDEA has guessed what you are importing.)
  4. On the next page of the wizard, specify the project root directory. Define your import preferences, if they differ from those specified in the Maven Integration dialog. Click Environment settings to configure Maven environment settings.

    Click Next.

  5. On the next page of the wizard, select the desired profiles, and click Next.

    Note that the Select profiles page appears if your root directory contains more than one pom.xml and the Search for projects recursively check box is selected.

  6. On the next page of the wizard, select the projects to be imported. Note that IntelliJ IDEA detects Maven projects by scanning the specified root. Click Next.
  7. On the next page of the wizard, select the project's SDK. Click Next.
  8. On the next page of the wizard, specify the new project name and location of the project files. Click Finish.

Working with Project Structure

After importing a Maven project, check its project structure to make sure that the Maven structure was imported as well.

  1. On the main menu select File | Project Structure.
  2. On the page that opens, check that the appropriate libraries and dependencies were downloaded.

You can download an external maven library to your project using Project Structure dialog.

  1. Open Project Structure page, from the left-hand pane, select Libraries, click /help/img/idea/2017.1/new.png icon and from the drop-down list, select From Maven.
    The Download Library from Maven Repository window opens.
  2. Start typing the name of the library in the search field and select your target from the search results' list.
  3. Select Download to check box, enter the location to which you want to download the library and press OK. By default, the Download to check box is cleared and IntelliJ IDEA downloads the library to the local repository.
  4. In the window that opens, select the module to which you want to add the maven library and press OK.
  5. As a result, IntelliJ IDEA adds the library to your dependencies' list. When you open the project, IntelliJ IDEA synchronizes such libraries. It might be helpful if the libraries were deleted from your computer or the project was taken from the VCS and libraries haven't been downloaded yet.
    The library is also added to your project tool window.

Working with POM

The code assistance is available when you work with POM in the editor. You can generate a new dependency and manage it. You can also add dependency, repository or plugin templates.

  1. Open your POM file and in the editor and press Alt + Insert.
  2. From the list that opens, select an item that you want to generate, for example, a dependency.
  3. In the window that opens search for the artifact that you want to add and click Add. If you don't remember the full name of an artifact you can enter part of the groupId and part of the artifactId separated by a colon (:).
    You can search either based on the name of artifact or the name of a class.

Working with Maven Tool Window

After creating a new or importing an existing Maven project, IntelliJ IDEA displays the maven model inside the Maven tool window. You can use the Maven tool window to run maven goals, create run/debug configurations, show dependencies, customize the goal execution and perform other useful tasks.

  1. On the main menu click View | Tool Windows | Maven Projects to open the Maven tool window.
  2. You can perform the following tasks:
    • run goals
      Click /help/img/idea/2017.1/maven_goal_icon.png Execute Maven Goal icon.
    • create run/debug configuration for the list of goals
      Highlight the goals you want to run, right-click on them and from the context menu select Create 'mvn [name of a goal]'.
      In the window that opens, specify run/debug configuration settings and click OK.
    • display dependencies
      Click Show Dependencies icon.
    • set triggers for running maven goals
      Right-click on the goal and from the context menu select at what point IntelliJ IDEA should run your goal.
      As a result, the trigger for the goal execution is displayed next to the selected goal.
    • assign a shortcut for running maven goal
      Right-click on the goal and from the context menu select Assign Shortcut.
      In the window that opens, add the shortcut and press OK.

Working with Maven Settings

IntelliJ IDEA lets you change maven settings that are specific for your current project. Under Maven category you can find a number of options that can help you configure how your project is set up.

For example, you can choose to work in offline mode, add repositories or change how things are imported in your project.

  1. On the main menu select File | Settings | Build, Execution, Deployment | Build Tools | Maven.
  2. In the window that opens specify settings for your current maven project and click OK.

See Also


Last modified: 18 July 2017