IntelliJ IDEA 2016.3 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.
    /help/img/idea/2016.3/creat_maven_project.png
  3. On the next page of the wizard, specify properties for your Maven project and click Next.
    /help/img/idea/2016.3/new_maven_proj.png
  4. On the next page of the wizard, specify project's information and click Finish.
    /help/img/idea/2016.3/new_maven_proj_page2.png

    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.
    /help/img/idea/2016.3/maven_select_dir_for_import.png
  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.)
    /help/img/idea/2016.3/maven_import_model.png
  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.

    /help/img/idea/2016.3/maven_import_rootdir_page.png
  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.
    /help/img/idea/2016.3/maven_import_select_proj_to_import.png
  7. On the next page of the wizard, select the project's SDK. Click Next.
    /help/img/idea/2016.3/maven_import_select_sdk.png
  8. On the next page of the wizard, specify the new project name and location of the project files. Click Finish.
    /help/img/idea/2016.3/maven_import_proj_info.png

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.
    /help/img/idea/2016.3/maven_project_structure.png

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/2016.3/new.png icon and from the drop-down list, select From Maven.
    /help/img/idea/2016.3/maven_new_lib.png
    The Download Library from Maven Repository window opens.
    /help/img/idea/2016.3/maven_download_from_repos.png
  2. Start typing the name of the library in the search field and select your target from the search results' list.
    /help/img/idea/2016.3/maven_download_from_repos2.png
  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.
    /help/img/idea/2016.3/maven_download_to.png
  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.
    /help/img/idea/2016.3/maven_added_lib_ps.png
    The library is also added to your project tool window.
    /help/img/idea/2016.3/maven_added_lib_pv.png

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.
    /help/img/idea/2016.3/maven_generate.png
  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 (:).
    /help/img/idea/2016.3/maven_search_artifact.png
    You can search either based on the name of artifact or the name of a class.
    /help/img/idea/2016.3/maven_search_class.png

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.
    /help/img/idea/2016.3/maven_tool_window.png
  2. You can perform the following tasks:
    • run goals
      Click /help/img/idea/2016.3/maven_goal_icon.png Execute Maven Goal icon.
      /help/img/idea/2016.3/maven_exec_maven_goal.png
    • 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]'.
      /help/img/idea/2016.3/maven_create_run_debug_for_goals.png
      In the window that opens, specify run/debug configuration settings and click OK.
      /help/img/idea/2016.3/maven_run_debug_config_for_goals.png
    • display dependencies
      Click Show Dependencies icon.
      /help/img/idea/2016.3/maven_show_dependencies.png
    • 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.
      /help/img/idea/2016.3/maven_customize_goal_exec.png
      As a result, the trigger for the goal execution is displayed next to the selected goal.
      /help/img/idea/2016.3/maven_customize_goal_exec_result.png
    • assign a shortcut for running maven goal
      Right-click on the goal and from the context menu select Assign Shortcut.
      /help/img/idea/2016.3/maven_goal_shortcut.png
      In the window that opens, add the shortcut and press OK.
      /help/img/idea/2016.3/maven_keymap_dialog.png

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.

/help/img/idea/2016.3/maven_setiings_categories.png
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.
    /help/img/idea/2016.3/maven_settings.png
  2. In the window that opens specify settings for your current maven project and click OK.

See Also

Concepts:

Last modified: 29 November 2016