How to parameterize maven goals?

Answered

How do you pass parameters to maven goals windoow (right hand side) like -DskipTests=true. I couldn't find how to costomize a goal.

10 comments
Comment actions Permalink

For a global switch (which will apply to all goals when run), open the Maven settings (you can either click the wrench icon in the maven tool window, or go to Settings (Ctrl+Alt+S) > Project Settings > Maven. Expand the "Maven" node on the left and select "runner". There you can add any VM options and/or properties to be passed into maven. There is also a "Skip Tests" option you can select. Again, this will apply to all maven goals for the project. See Reference > Settings Dialog > Project Settings > Maven in the help guide or the online web help for more information.

To configure for a specific goal so that the switches apply only to that goal, you need to run the gaol via a run configuration. Create a run configuration for the goal (right click the goal and select Create "{pomName} [{goal}]"). When editing the goal, select the runner tab. There you can add any VM options and/or properties to be passed into maven. There is also a "Skip Tests" option you can select. You will then need to run the goal via the run configuration. It will be listed in the run configurations drop down in the toolbar. Or you can type Ctrl+Alt+F10 to open a popup of all the run configurations. See References > Dialogs > Run/Debug Configurations > Run/Debug Configuration: Maven in the help guide or the online web help for more information.

Finally, if you want all new maven run configurations to have a particular default, you can edit the default values for new maven run configurations. Open the "Edit Configurations" option from the run configurations drop down, or the Ctrl+Alt+F10 popup. On the left, expand the "Defaults" node. Find the Maven node under the Defaults node. Select it and edit the values on the Runner tab.

I hope that helps.

Best Regards,
Mark

0
Comment actions Permalink

Thanks, very helpful.

It'd be nice if IDEA includes the custom maven run config right under the lifecycle goal (package-skip-tests), instead of the user trying to pick one from the toolbar (and its several configs).

0
Comment actions Permalink

I wonder if there's a solution that works for passing -am parameter to mvn?
I tried to put it to VM options, but not surprisingly it does what it's name tells: it passes it to java, and java gives an error message that it doesn't recognize -am.

How can I pass -am to mvn?

0
Comment actions Permalink

Hello,

You may right click on maven goal, select "Create 'Unnamed'" and change command line there.

0
Comment actions Permalink

so I need to do it for each goal? I hoped there's a more general way.

0
Comment actions Permalink

You may change default "Maven" run debug configuration template ("Run | Edit Configurations - Templates - Maven").

0
Comment actions Permalink

Yaroslav Bedrov this question isn't about run configurations, look at the original question: "maven goals window (right hand side)"

 

0
Comment actions Permalink

It's not possible to change default command line used when goal is executed with double click. Feel free to create feature request on YouTrack: http://youtrack.jetbrains.com/issues/IDEA.

0

Please sign in to leave a comment.