zoukankan      html  css  js  c++  java
  • Gradle Goodness: Continue Build Even with Failed Tasks

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

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

    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 has failed and only the task failTask is executed. Now we run the same two 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 time the successTask is executed even though the failTask has failed again. Gradle will keep track of all tasks that have failed and displays a summary with all the tasks that have failed.

    Written with Gradle 2.2.1

  • 相关阅读:
    FTP上传/下载文件栗子
    WEB上传大文件解决方案
    SQL分页新语法
    CTE实现树形结构查询
    无索引状态下比较DataTable的几种过滤方法效率
    CodeSmith模板
    一. DotNet MVC4.0+EasyUI Web简单框架-前言
    关于Winform 2.0以后多线程不能更新UI的办法
    NHibernate Demo 和 效率测试
    构建Vue+Ionic+Cordova项目,开发全平台APP系列教程
  • 原文地址:https://www.cnblogs.com/GoAhead/p/4187479.html
Copyright © 2011-2022 走看看