在 Jacoco 的 jacocoTestReport.xml 文件中包含多个源集

Include multiple sourcesets in the Jacoco's jacocoTestReport.xml file

我在基于 Gradle 的项目中定义了一个自定义源集,如下所示:

sourceSets {
    componentTest {
        java {
            compileClasspath += main.output + test.output
            runtimeClasspath += main.output + test.output
            srcDir file('src/componentTest/java')
        }
    }
}

configurations {
    componentTestImplementation.extendsFrom testImplementation
}

task componentTest(type: Test) {
    dependsOn assemble
    testClassesDirs = sourceSets.componentTest.output.classesDirs
    classpath = sourceSets.componentTest.runtimeClasspath
    outputs.upToDateWhen { false }
    testLogging.showStandardStreams = true
    mustRunAfter(test)
}

check.dependsOn(componentTest)

sourceSet 包含 Cucumber 特征。

当 运行 Jacoco 时,生成的 jacocoTestReport.xml 文件似乎不包含 Cucumber 测试生成的覆​​盖范围。

这是 Jacoco 配置:

jacocoTestReport {
    executionData(
            file("${project.buildDir}/jacoco/test.exec"),
            file("${project.buildDir}/jacoco/componentTest.exec"),
    )
}

我可以做些什么来使 xml 文件中的覆盖范围与我在 exec 文件中的覆盖范围相同吗?

经过进一步的实验,xml 文件包含来自 componentTest sourceSet 的覆盖范围。

我问这个问题是因为覆盖率没有在 SonarQube 中正确反映 - 我在 SonarQube 的 componentTest 中看不到 Cucumber 测试。但现在在我看来,实际覆盖值与 Jacoco 报告显示的一致。我只需要在 SonarQube 中排除与 Jacoco 中相同的来源 类。