Monday, February 15, 2010

MojoFailureException vs. MojoExecutionException

There are two types of wrapper exceptions commonly used in Maven plugins, the MojoFailureException and MojoExecutionException. It's not obvious which one is the correct one to use, so here is a simple explanation. A MojoExecutionException typically means that an unexpected and unrecoverable error happened while running the plugin. This would be something like a NullPointerException or other RuntimeException that the plugin developer did not expect and/or can not handle. It's basically a plugin crash.

A MojoFailureException means that there was a problem in the build which the plugin detected, and the plugin is now notifying you of that failure. This would be something like a Java source file that couldn't compile. The build can not continue, but the plugin is still working normally.

More information can be found in the Sonatype Maven book.

No comments: