在Gradle中跳过残疾任务的依赖执行? [英] Skipping dependency execution of a disabled task in Gradle?

查看:190
本文介绍了在Gradle中跳过残疾任务的依赖执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这个任务被跳过时,不执行任务的依赖关系是否有可能?

Is it somehow possible to not execute the dependencies of a task when that task will be skipped?

在下面的例子中,我如果有的话,就像 jar (以及 jar 的依赖关系)执行 runServerTests 时,服务器已经在运行。在这种情况下,服务器将由另一个进程启动。

In the example below, I'd like jar (and the dependencies of jar) to not be executed if a server is already running when executing runServerTests. The server would in this case be started by another process.

apply plugin: 'java'

task startServerIfNotRunning(dependsOn: jar) {
  onlyIf { isServerNotRunning() }
  ...
}

task runServerTests(dependsOn: startServerIfNotRunning) { ... }

我宁愿不添加 onlyIf jar 任务,因为总是应该执行的其他任务可能取决于那个任务。 jar 任务也有自己的依赖。

I'd rather not add an onlyIf to the jar task, since other tasks that always should be executed may be depending on that one. The jar task also has dependencies of its own.

推荐答案

所需的行为,您必须将任务从任务执行图中排除,而不是跳过其执行。您可以使用 -x 从命令行或以 gradle.startParameter.excludedTaskNames<<< ... gradle.taskGraph.useFilter {task - > ...}

To get the desired behavior, you have to exclude the task from the task execution graph, rather than skipping its execution. You can do this with -x from the command line or programmatically with gradle.startParameter.excludedTaskNames << "..." or gradle.taskGraph.useFilter { task -> ... }.

这篇关于在Gradle中跳过残疾任务的依赖执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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