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