运行另一个任务时跳过一个任务 [英] Skip a task when running another task

查看:73
本文介绍了运行另一个任务时跳过一个任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在gradle项目中添加了一个任务:

I added a task to my gradle project:

task deploy() {
    dependsOn "build"
    // excludeTask "test"  <-- something like this

    doFirst {
       // ...
    }
}

现在,build任务始终在deploy任务之前运行.这很好,因为构建任务包括许多步骤.现在,我要明确禁用其中包含的任务之一.

Now the build task always runs before the deploy task. This is fine because the build task has many steps included. Now I want to explicitly disable one of these included tasks.

通常我在命令行中使用

gradle deploy -x test

如何以编程方式排除test任务?

How can I exclude the test task programmatically?

推荐答案

您需要配置任务图,而不是配置deploy任务本身.这是您需要的代码:

You need to configure tasks graph rather than configure the deploy task itself. Here's the piece of code you need:

gradle.taskGraph.whenReady { graph ->
    if (graph.hasTask(deploy)) {
        test.enabled = false
    }
}

这篇关于运行另一个任务时跳过一个任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆