AbstractMavenMojo 的执行方法声明它抛出两个异常:MojoExecutionException 和 MojoFailureException。抛出任一结果都会导致构建停止,并且日志在每种情况下都会显示几乎相同的消息。
MojoExecutionException 的消息是:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] [exception text]
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
MojoFailureException 的消息是:
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] [exception text]
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
什么时候应该抛出哪个异常以及为什么?
最佳答案
如果问题导致无法继续构建,您似乎应该抛出 MojoExecutionException
,否则使用 MojoFailureException
。
您可以控制运行 maven 时处理 MojoFailureExpections
的行为。
以下链接详细说明了差异:https://books.sonatype.com/mvnref-book/reference/writing-plugins-sect-custom-plugin.html#writing-plugins-sect-failure
链接损坏?谷歌搜索
sonatype writing-plugins-sect-custom-plugin writing-plugins-sect-failure
关于maven-2 - 何时在 Maven 中使用 MojoExecutionException 与 MojoFailureException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1033154/