2

我正在开发一个使用com.sun.tools.javadoc包的 maven 插件。

在我的 Abstract 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] 
4

0 回答 0