Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle execute task after test phase even if test has failed

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.

like image 569
Yurii Bondarenko Avatar asked Jan 07 '14 13:01

Yurii Bondarenko


People also ask

How do I run Gradle without a test?

To skip any task from the Gradle build, we can use the -x or –exclude-task option. In this case, we'll use “-x test” to skip tests from the build. As a result, the test sources aren't compiled, and therefore, aren't executed.

Does Gradle build run all tasks?

You can execute multiple tasks from a single build file. Gradle can handle the build file using gradle command. This command will compile each task in such an order that they are listed and execute each task along with the dependencies using different options.

Does Gradle run tests in parallel by default?

Parallel execution Yet Gradle will only run one task at a time by default, regardless of the project structure (this will be improved soon). By using the --parallel switch, you can force Gradle to execute tasks in parallel as long as those tasks are in different projects.


1 Answers

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.

like image 73
Peter Niederwieser Avatar answered Oct 09 '22 05:10

Peter Niederwieser