我正在开发一个使用 com.sun.tools.javadoc 包的maven插件。
在我的抽象mojo类中,我有这个,
@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"});
}
}
在我的SimpleCheck.java文件中,我抛出异常。
public class SimpleCheck {
public static boolean start(RootDoc root) throws IOException, ParseException, MojoFailureException {
throw new MojoFailureException("test");
}
}
正如预期的那样,抛出异常。
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
为什么构建仍然是成功的。不应该抛出抛出的异常使构建失败。在 MojoFailureException 的文档中,它说,
执行插件期间发生的异常(例如编译失败)。 抛出这个例外导致" BUILD FAILURE"要显示的消息。
为什么在这种情况下它没有发生。
注意:我试图在GreetingMojo.java类中抛出异常。抛出异常后构建失败了。
[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]