Tuesday, June 09, 2015

Selectively run Maven phases and goals from Eclipse IDE

CALL FOR ACTION: If you like this feature please vote up on 470138.


1129 installs from Eclipse Marketplace so far.



This kinda answers this SO question.

Recent updates:
  • Save named configurations
  • The dialog is now mode less, thus allowing multiple invocations. If there is are multiple Maven projects in the workspace, a selector to invoke Phases and Goals on selected other project is shown.
  • Run goals in selection order instead of build agenda order. Using this mode you can run goals in any order. An astute reader may note that you can also type goals in text area before running them. This allows you to even run goals not associated with any phase.
  • Selecting a phase selects the associated goals
  • Expand all Phases
  • Expand all/Collapse all
  • If there is only one Maven project in the workspace, that is always selected.
  • Added a simple Maven Build Spy. It shows the success or failure of the goals, the timing and the exception message as a tooltip for failed goals.


You can even use the spy in your maven builds by:
  • Downloading the Maven Build Spy jar.
  • And then passing the following parameter to your mvn build like so:
> mvn -Dmaven.ext.class.path=path-to/mavenbuildspy.jar ....

When you run a phase, Maven runs all the preceding phases as per the lifecycle definition. However, sometimes I only want to run a selective subset of phases. The only way to do that is to actually run the goals associated with those phases explicitly. However how to get that list of goals? One would think that running:

> mvn help:describe -Dcmd=deploy

would do the trick. But alas it does not. It only lists the statically associated goals as per the static lifecycle definition - and not the actual goals you may configured in the pom's plugin configuration section. IMO this is simply - unimplemented yet useful functionality of Maven.

In this blog entry I talked about listing phases and actual associated goals of a maven lifecycle of a maven pom. In it I talked about an Eclipse plugin based on m2e code. I have improved it further. Now you can show the phases and goals in a checked tree dialog using the Project > Phases and Goals command.

You can run the selected phases or goals using the Launch selected goals command. When a phase is selected all goals associated with that phase are run. In Single Selection Mode the goals simply get added to the set in the order in which they were selected. This allows execution of orders in any order you want.

Maven 3.3.1 or greater is required to run the goals.

NOTE: If you install external Maven 3.3.1+ and try to use it as the installed Maven using Window > Preferences > Maven > Installations you may see an error during the build:

-Dmaven.multiModuleProjectDirectory system property is not set...

To fix that configure the property in your JDK/JRE installation using Window > Preferences > Java > Installed JREs > select default JDK/JRE > edit.

- See more at: http://marketplace.eclipse.org/content/phases-and-goals

You can print the listing to the Maven Console using the Log All command.


To use
  • Make sure you have m2e plugins installed into your Eclipse.
  • Then install the fragement from this update site URL:
https://cdn.rawgit.com/sandipchitale/m2e-phasesandgoals/1.0.28/org.eclipse.m2e.core.ui.phasesandgoals.updatesite/site.xml

or use:

Drag to your running Eclipse workspace to install Phases and GOals

button.


Current standing see: Eclipse Marketplace

  • Restart Eclipse
  • Select a maven project node and invoke Project > Show Phases and Goals command. You will see the output like above in the Maven Console. If a resource from Maven Project is not selected you are prompted to select on.
Github

https://github.com/sandipchitale/m2e-phasesandgoals


BTW This is implemented as a fragment for https://github.com/eclipse/m2e-core/tree/master/org.eclipse.m2e.core.ui

Enjoy!

Sunday, June 07, 2015

List Maven POMs phases and goals bounds to the phases

For longest time I have wanted to be able to show the actual goals associated with the phases of maven lifecycles. There is the following maven command:

> mvn -B help:describe -Dcmd=deploy

but alas it only lists the static set of goals associated with the phases as specified in the original lifecycle. And then it struck me that m2e add the Lifecycles section to the Maven project's properties page.


So I git cloned the m2e repo  https://git.eclipse.org/r/m2e/m2e-core , looked through the code and
the wrote a small Eclipse plugin fragment to add a command to list the phase and goals into the console. Here is the result.


To use
  • Make sure you have m2e plugins installed into your Eclipse.
  • Then install the fragement from this update site URL:
https://cdn.rawgit.com/sandipchitale/m2e-phasesandgoals/master/org.eclipse.m2e.core.ui.phasesandgoals.updatesite/site.xml
  • Restart Eclipse
  • Select a maven project node and invoke Project > Show Phases and Goals command. You will see the output like above in the Maven Console.
Update

Now displays likely lifecycle and execution ids.

TODO
  • Show the output in a tree view.
  • Allow the user to launch mvn build with the goals associated with a phase.
Github

https://github.com/sandipchitale/m2e-phasesandgoals