gpt4 book ai didi

gradle - Gradle --continue选项不适用于TaskExecutionListener

转载 作者:行者123 更新时间:2023-12-03 06:19:45 25 4
gpt4 key购买 nike

在我的gradle文件中,我有Test类型的3个任务,如下所示:

/**
* This is a test block called 'sampleA' to run testng tests.
*/
task sampleA(type: Test) {
include "**/Helloworld4a*"
}

/**
* This is a test block called 'sampleB' to run testng tests.
*/
task sampleB(type: Test) {

include "**/Helloworld4b*"
}

/**
* This is a test block called 'sampleC' to run testng tests.
* This block depends on sampleB block.
*/
task sampleC(type: Test, dependsOn: sampleB) {

include "**/Helloworld4*"
exclude "**/Helloworld4a*"
exclude "**/Helloworld4b*"
}

现在,我创建了一个插件,在其中添加了TaskExecutionListener。在TaskExecutionListener中,无论任务是否成功执行,我都仅为每个任务创建一个文件。
  • sampleA将测试失败
  • sampleB将测试失败
  • sampleC将不会失败o​​jit_rli

    当我运行gradle sampleA sampleB sampleC时,它仅运行sampleA,这是预期的(因为任务失败)
    但是当我使用--continue选项时,结果是一样的。没有添加侦听器,我看到sampleAsampleB都在运行。

    这是我的侦听器类
    class TestInfraTaskListener implements TaskExecutionListener {
    /**
    * Generate the test results for the EMTestNGTest types
    */
    public void afterExecute(Task task, TaskState state) {
    if(task instanceof Test) {
    /* If testng test type, then generate results. */
    def resultHandler = new TestResultsHandler(task, state)

    /* Generate individual result files */
    resultHandler.generateResultFiles()

    resultHandler.uploadToJira()
    state.rethrowFailure()
    }
    }
    }

    当我设置ignoreFailure = true时,所有3个任务都将运行。我在这里做错了什么。我只希望sampleAsampleB--continue选项一起运行。

    我的Gradle版本是1.11(我无权升级)

  • 最佳答案

    好的,终于可以按照以下规则使用它了:

  • 不要在ignoreFailures = true任务
  • 中设置 Test
  • 在任何情况下(无论任务成功还是失败)都不要调用state.rethrowFailure()throw new GradleException(...)

  • 关于gradle - Gradle --continue选项不适用于TaskExecutionListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27150667/

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