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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With