views:

219

answers:

1

The AbstractMavenMojo's execute method declares it throws two exceptions, MojoExecutionException and MojoFailureException. Throwing either results in the build stopping and the log displays an almost identical message in each case.

The message for MojoExecutionException is:

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] [exception text]
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------

and the message for MojoFailureException is:

[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] [exception text]
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------

When should you throw which exception and why?

+1  A: 

It seems you should throw a MojoExecutionException if the problem makes it impossible to continue with the build, and use the MojoFailureException otherwise.

You can control the behavior for handing MojoFailureExpections when maven is run.

The following link details the difference: http://www.sonatype.com/books/maven-book/reference/writing-plugins-sect-failure.html

Kingamajick
thanks that is exactly what I was after
Rich Seller