Gradle goodness:continue Build even with Failed Tasks

Source: Internet
Author: User
Tags stack trace

If We run a Gradle build and one of the tasks fails, the whole build stops immediately. We have the fast feedback of our build status. If we don ' t want to this and want Gradle to execute all tasks, even though some might has failed, we use the command line Option --continue . When we use the --continue command line option Gradle would execute every task where the dependent tasks is not failing. This was also useful in a multi-module project where we might want to build all projects even though some could have failing Tests, so we get a complete overview of failed tests for all modules.

In the following Gradle build file, we have both tasks. The task failTask throws a to TaskExecutionException purposely fail the task. The would not successTask fail:

View Sourceprint? 00. task failTask << { task -> 01. println "Running ${task.name}" 02.  03. throw new TaskExecutionException( 04. task, 05. new Exception( ‘Fail task on purpose‘ )) 06. } 07.  08. task successTask << { 09. println "Running ${it.name}" 10. }

Let's run both tasks from the command line and see the output:

$ gradle failTask successTask :failTask Running failTask :failTask FAILED  FAILURE: Build failed with an exception.  * Where: Build file ‘/Users/mrhaki/samples/gradle/continue/build.gradle‘ line: 4  * What went wrong: Execution failed for task ‘:failTask‘. > Fail task on purpose  * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  BUILD FAILED  Total time: 4.148 secs $

We See the build have failed and only the task is failTask executed. Now we run the same to the tasks, but we use the command line option --continue :

$ gradle --continue failTask successTask :failTask Running failTask :failTask FAILED :successTask Running successTask  FAILURE: Build failed with an exception.  * Where: Build file ‘/Users/mrhaki/samples/gradle/continue/build.gradle‘ line: 4  * What went wrong: Execution failed for task ‘:failTask‘. > Fail task on purpose  * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.  BUILD FAILED  Total time: 6.918 secs $

This was successTask executed even though the has failTask failed again. Gradle would keep track of all tasks, which has failed and displays a summary with all the tasks, that has failed.

Written with Gradle 2.2.1

Gradle goodness:continue Build even with Failed Tasks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.