gpt4 book ai didi

android - "connectedAndroidTest"任务成功后运行gradle task X

转载 作者:行者123 更新时间:2023-11-29 17:25:36 26 4
gpt4 key购买 nike

我有一个 gradle taskX,我想在 connectedAndroidTest 任务完成后运行,但前提是所有测试都通过 connectedAndroidTest

我怎样才能做到这一点?

最佳答案

您需要利用 finalizedBy以及特定任务的状态检查。方法如下:

task connectedAndroidTest << {
logger.lifecycle("Running $name")
if (project.hasProperty('lol')) {
throw new Exception('lol')
}
}

task taskX << {
def failure = tasks.connectedAndroidTest.state.failure
if(!failure) {
logger.lifecycle("$name is finalizer")
} else {
logger.lifecycle("$tasks.connectedAndroidTest.name failed, nothing to do.")
}
}

connectedAndroidTest.finalizedBy(taskX)

现在如果运行:

gradle cAT

输出将是:

:connectedAndroidTest
Running connectedAndroidTest
:taskX
taskX is finalizer

BUILD SUCCESSFUL

Total time: 1.889 secs

This build could be faster, please consider using the Gradle Daemon: https://docs.gradle.org/2.8/userguide/gradle_daemon.html

时间:

gradle cAT -Plol

运行,则输出为:

:connectedAndroidTest
Running connectedAndroidTest
:connectedAndroidTest FAILED
:taskX
connectedAndroidTest failed, nothing to do.

FAILURE: Build failed with an exception.

* Where:
Build file '/Users/opal/tutorial/stackoverflow/34797260/build.gradle' line: 4

* What went wrong:
Execution failed for task ':connectedAndroidTest'.
> lol

* 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: 1.931 secs

Here可以找到演示。

  [1]: https://docs.gradle.org/current/javadoc/org/gradle/api/Task.html#finalizedBy(java.lang.Object...)

关于android - "connectedAndroidTest"任务成功后运行gradle task X,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34797260/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com