I'm developing a maven plugin which uses the com.sun.tools.javadoc package.
In my Abstract mojo class I have this,
@Mojo(name = "scan")
public class GreetingMojo extends AbstractMojo {
public void execute() throws MojoExecutionException {
Main.execute(new String[]{"-doclet", "my.plugin.SimpleCheck", "-docletpath"
, "."
, "-sourcepath"
, "./src/main/java"
, "-subpackages"
, "com.my.system"});
}
}
In my SimpleCheck.java file I'm throwing the exception.
public class SimpleCheck {
public static boolean start(RootDoc root) throws IOException, ParseException, MojoFailureException {
throw new MojoFailureException("test");
}
}
And as expected the exception is thrown.
javadoc: error - In doclet class my.plugin.SimpleCheck, method start has thrown an exception java.lang.reflect.InvocationTargetException
org.apache.maven.plugin.MojoFailureException: test
........
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
1 error
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.943 s
Why the build is still a success. Shouldn't the thrown exception fail the build. In the docs for MojoFailureException it says,
An exception occurring during the execution of a plugin (such as a compilation failure). Throwing this exception causes a "BUILD FAILURE" message to be displayed.
Why in this case it's not happening.
NOTE : I tried to throw the exception in my GreetingMojo.java class. Then the build got failed after throwing the exception.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.467 s
[INFO] Finished at: 2017-12-25T22:44:36+05:30
[INFO] Final Memory: 5M/112M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal my.plugin:my-maven-plugin:1.0-SNAPSHOT:scan (default-cli) on project abcmanager: test throw in GreetingMojo -> [Help 1]
[ERROR]