Java 即使测试失败,Gradle 也会在测试阶段后执行任务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20973365/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Gradle execute task after test phase even if test has failed
提问by Yurii Bondarenko
I am using gradle as my builder. After running all of my test I want to execute additional task. If there are no test failures
我使用 gradle 作为我的构建器。运行完所有测试后,我想执行其他任务。如果没有测试失败
test.doLast { /*my task*/ }
works fine. But if there is at least one test failure my task does not execute.
工作正常。但是如果至少有一个测试失败,我的任务就不会执行。
Is there a way to execute my task even if some of my test failed.
即使我的某些测试失败,有没有办法执行我的任务。
采纳答案by Peter Niederwieser
test.doLast
doesn't add a new task, but adds another task actionto the test
task. What you can do instead is to declare a finalizer task:
test.doLast
不添加新任务,而是向任务添加另一个任务操作test
。你可以做的是声明一个终结器任务:
task foo(type: ...) { ... } // regular task declaration
test.finalizedBy(foo)
This way, foo
will run even if test
has failed, similar to a Java finally
block.
这样,foo
即使test
失败也会运行,类似于 Javafinally
块。