IntelliJ IDEA 2019.2 Help

Work with Maven goals

IntelliJ IDEA lets you run, debug and manage Maven goals in your project.

Run Maven goals

You can use several way to run Maven goals such as use the Run Anything window, use the context menu in the Maven tool window, or create a run configuration for one or several Maven goals.

Run a Maven goal from the Run Anything window

  1. In the Maven tool window, on the toolbar, click the Execute Maven Goal button. Alternatively, press Ctrl twice to open the Run Anything window.

    Run Anything dialog

  2. In the Run Anything window, start typing a name of the goal you want to execute. The window also displays a list of recent Maven goal entries.

    If you have a multi-module project and need to execute a goal from the specific module, enter a name of your module first and then the goal's name. For example, mvn module1 test

    Run Anything / Maven goal
  3. IntelliJ IDEA runs the selected goal and displays the result in the Run tool window.

    Maven Run tool window

Run a Maven goal from the context menu

  1. In the Maven tool window, click Lifecycle to open a list of Maven goals.

  2. Right-click the desired goal and from the context menu select Run 'name of the goal'. IntelliJ IDEA runs the specified goal and adds it to the Run Configurations node.

Run a Maven goal or a set of goals via Run configuration

IntelliJ IDEA lets you create a run configuration for one specific goal or a set of several goals.

  1. In the Maven tool window, click Lifecycle to open a list of Maven goals.

  2. Right-click a goal for which you want to create a Run configuration. (To select several Maven goals, press Ctrl and highlight the desired goals.)

  3. From the list select Create 'goal name'.

  4. In the Create Run/Debug Configuration: 'goal name' dialog, specify the goal settings (you can specify any Maven commands and arguments) and click OK.

    the context menu
    IntelliJ IDEA displays the goal under the Run Configurations node.
    the Run Configurations node

  5. Double-click the goal to run it or right-click the goal and from the context menu select Run.

Configure triggers for Maven goals

IntelliJ IDEA lets you run Maven goals before your project's execution or set other conditions using the goal activation configuration.

  1. In the Maven tool window, click Lifecycle to open a list of goals.

  2. In the list that opens, right-click the goal for which you want to set a trigger.

  3. From the context menu, select an activation phase. For example, Execute Before Build.
    the Execute Before Build option

    The name of activation phase is added to the selected goal in the Maven tool window.

    Maven goal with the trigger

You can also create a run/debug configuration that would depend on a Maven goal.

  1. From the main menu, select Run | Edit Configurations to open the run/debug configuration for your project.

  2. In the Run/Debug Configurations dialog, in the Before Launch section, click the icons general add svg icon.

  3. In the list that opens, select Run Maven Goal.

    the Run/Debug configuration: Before Launch

  4. In the Select Maven Goal dialog, specify a project and a goal that you want to execute before launching the project.

    Select Maven Goal

  5. Click OK.

Associate Maven goals with keyboard shortcuts

You can associate a Maven goal with a keyboard shortcut and execute goals with a single key-stroke.

  1. In the Maven tool window, right-click the desired goal.

  2. From the context menu, select Assign Shortcut. The Keymap dialog opens.

  3. In the Keymap dialog, under the Maven node navigate to your goal.

  4. Right-click the goal and from the list that opens, select a type of the shortcut you want to assign.

    the Keymap dialog

  5. In the dialog that opens, depending on the shortcut's type, configure your shortcut and click OK.

    the Keyboard Shortcut dialog
    The shortcut is displayed against your goal in the Maven tool window.

While in the Keymap dialog, you can add a new goal to which you want to assign a shortcut.

  1. In the Keymap dialog, under the Maven node, click Choose a phase/goal to assign a shortcut.

  2. In the dialog that opens, select a goal you need and click OK.

    the Choose Maven Goal dialog
    The goal is added to the list under the Maven node. Now you can configure the shortcut.

Debug Maven goals

IntelliJ IDEA lets you create a debug configuration for one or several Maven goals. You can also select a goal in the Maven tool window and start a debugging session.

Create a debug configuration for Maven

  1. From the main menu, select Run | Edit Configurations to create a Maven run/debug configuration.

  2. In the dialog that opens, on the left side, click icons general add svg to open the Add new Configuration list.

  3. From the list that opens, select Maven to create a new Maven configuration.

  4. On the right side of the dialog, specify the information, such as a name of your configuration, your project's directory, command line parameters, and profiles. You can leave the default settings for the rest. Click OK.

  5. From the main menu, click icons actions startDebugger svg to start your debugging session.

Debug a Maven goal

You can start a debugging session for a single Maven goal or a Maven run configuration that may contain more than one Maven goal.

  1. Open the Maven tool window.

  2. Under the Lifecycle node, select a goal for which you want to start a debugging session. (Look for existing Maven run configurations under the Run Configurations node to start a debugging session for the created configuration.)

  3. Right-click the goal and from the context menu select Debug [name of the goal]. IntelliJ IDEA starts a debugging session.

Last modified: 17 October 2019