Gradle execute task after test phase even if test

2019-04-03 05:51发布

问题:

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

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.

回答1:

test.doLast doesn't add a new task, but adds another task action to the test task. What you can do instead is to declare a finalizer task:

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.