Gradle - 在所有子模块的测试阶段之后运行 testReport 任务

Fra*_*man 3 gradle

我有一个带有子项目的简单项目,我想在执行gradle test命令时为所有测试生成汇总报告。

我遵循了gradle 文档并添加了以下内容:

task testReport(type: TestReport) {
    // make sure this task is run after all subproject test tasks
    mustRunAfter subprojects*.test

    destinationDir = file("$buildDir/reports/allTests")
    // Include the results from the `test` task in all subprojects
    reportOn subprojects*.test
}
Run Code Online (Sandbox Code Playgroud)

这在我执行时有效gradle test testReport,但是当我执行gradle testgradle build在根项目中时 - 任务testReport未运行。

如何让 gradle 运行任务而不每次都指定它?

RaG*_*aGe 5

添加:test.finalizedBy 'testReport'到你的 build.gradle; 只是在根级别,不必在任何闭包内。

taskX.finalizedBy taskY
Run Code Online (Sandbox Code Playgroud)

每次 taskX 成功完成执行时都会运行 taskY。