IntelliJ IDEA 2019.1 Help

Work with Maven goals

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

Run Maven goals

IntelliJ IDEA lets you run Maven goals using several ways. You can run a Maven goal from a command line, use the context menu in the Maven Projects tool window, or create a run/debug configuration to run one or several Maven goals.

Moreover, when you work in the distraction-free mode (without toolbars and tool windows), you can run Maven goals or commands from the Run Anything window. Press Ctrl twice to open it, type your command and press Enter.

Run Anything dialog

You can check the Mastering shortcuts section for more information.

Run a Maven goal from the command line

  1. In the Maven Projects tool window, on the toolbar, click the maven goal icon icon.

  2. In the Execute Maven Goal dialog, in the Command line field, start entering the name of your goal. You can see that IntelliJ IDEA displays the list of Maven goals from which you can select the appropriate one. Click Execute.

    maven exec 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 Projects 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 Projects 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.)

    maven several goals config

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

    maven tool window context menu

  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.

    maven goal run debug
    IntelliJ IDEA displays the goal under the Run Configurations node.
    maven runConfigurations display

  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 Projects 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.
    maven context menu trigger

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

    maven added trigger

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

  1. On 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 icon.

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

    maven run config run goal

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

    maven select 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 Projects tool window, right-click the desired goal.

  2. From the context menu, choose 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.

    maven shortcut keymap

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

    maven keyboard shortcut dialog
    The shortcut is displayed against your goal in the Maven Projects 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.

    maven choose goal
    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 or you can select a goal and start a debugging session.

  1. On 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 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. On the main menu, click icons actions startDebugger svg to start your debugging session.

You can also start a debugging session for a single Maven goal or a Maven run configuration that may contain more than one Maven goal in the Maven Projects tool window.

  1. Open the Maven Projects 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 run configuration.)

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

Run tests in Maven projects

IntelliJ IDEA lets you run tests using the default IntelliJ IDEA test runner. You can also pass Maven Surefire plugin parameters when you run JUnit or TestNg tests and Maven Failsafe plugin parameters for running integration tests. The Maven surefire plugin is declared in the super POM by default, but you can adjust its settings in your project's POM.

You can create and run tests as you normally would for your Java project. See Performing Tests section.

You can run all your tests using a Maven goal or use Maven commands to run a single test.

  1. Open the Maven Projects tool window.

  2. Under the Lifecycle node select test. Note that goals specified in the Maven surefire plugin will be activated at this phase and all tests in a project or in a module will be run.

If you want to run just a single test instead of all the tests declared in your project, use the Maven -Dtest='TestName' test command.

  1. Open the Maven Projects tool window.

  2. On the toolbar, click the maven goal icon icon.

  3. In the Select Maven Goal dialog, specify a project or a module that contains your test and in the Command line field, enter the -Dtest='TestName' test command. Click Execute.

    maven run one test
    Maven runs the specified test and displays the result in the Run tool window.

Alternatively, you can create a Maven run configuration to run a single test using the same Maven command. The run configuration will be saved under the Run Configurations node.

  1. In the Maven Projects tool window, under the Lifecycle node, right-click the test goal.

  2. From the context menu, select Create 'name of the module/project and name of a goal'.

  3. In the dialog that opens, specify a working directory that contains test you want to run and in the Command line field, specify a phase (specified automatically) and the -Dtest='TestName' test command. Click OK.

    maven run config for test

  4. Open the Run Configurations node and double-click your configuration to run.

    maven saved config
    Maven runs the test and displays the result in the Run tool window.

You can skip running tests, for example, when you want to just compile your project and don't want to wait for Maven to complete the tests' execution.

  1. Click the icons general settings svg icon in the Maven Projects tool window to open Maven settings and select Runner from the options on the left.

  2. On the Runner page, select Skip tests and click OK.

    maven settings skipTests
    IntelliJ IDEA de-activates the test goal under the Lifecycle node.
    maven tool win skipTest
    The appropriate message notifying that tests are skipped is displayed in the Maven Run tool window when you execute other goals.
    maven run tool win notify

Last modified: 20 May 2019