多模块的 jacoco 配置不起作用

问题描述 投票:0回答:3

我的 jacoco 配置发生了一些奇怪的事情,我无法弄清楚。我在堆栈溢出和其他平台上访问了多个线程并尝试了很多东西,但没有解决这个问题。

我已经为多个模块设置了java代码覆盖率。这是我的项目结构

  • ABC

    • 模块1
  • 防御

    • 模块1
    • 模块2
    • 模块3

    pom.xml

我已经为我的 DEF maven 项目配置了 jacoco。我只是在配置我的 DEF 项目。这就是 pom.xml 包含的内容

    <plugin>
        <groupId>org.jacoco</groupId>
        <artifactId>jacoco-maven-plugin</artifactId>
        <version>0.8.8</version>
        <executions>
            <execution>
                <goals>
                    <goal>prepare-agent</goal>
                </goals>
            </execution>
            <execution>
                <id>report</id>
                <phase>prepare-package</phase>
                <goals>
                    <goal>report-aggregate</goal>
                </goals>
                <configuration>
                 <outputDirectory>${project.basedir}/target/reports</outputDirectory>
                </configuration>
                </execution>
        </executions>
    </plugin>

问题: 这里的问题是,它在每个模块 1、模块 2 和模块 3 中生成代码覆盖率报告。但是在 module1 中生成的报告不包含自身的代码覆盖率。意思是,它显示了 module2 和 module3 的代码覆盖率,但它本身不包括 module1 报告。我不知道怎么了?

编辑: DEF 中的模块是 Maven 模块,它不包含与 jacoco 相关的任何内容。

任何想法或任何建议?

谢谢

java sonarqube jacoco jacoco-maven-plugin jacoco-plugin
3个回答
2
投票

再创建一个模块作为 ReportAggregator 并将 jacoco 配置从父 pom 移动到 ReportAggregator pom


1
投票

谢谢@Sarang 的回复。它确实解决了我的问题,但之后我又遇到了一个问题,那就是我的一个模块没有生成 jacoco.exec 文件。经过一番调查,问题似乎出在

<argLine>
标签上。在我的一个模块中,我使用了这个标签,但不知何故它被覆盖了。

所以我所做的是在此之前预先附加

argLine
,它解决了我的问题

<configuration>
    <argLine>${argLine} -XX:PermSize=256m -XX:MaxPermSize=1048m</argLine>
</configuration>

0
投票

您可以尝试从应用程序模块合并单元测试和仪器测试:

task jacocoUiTestReportAllModules(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {
    group "Reports"
    description "Generate Jacoco Instrumented Tests coverage reports for all modules"
    reports {
        xml.enabled = true
        html.enabled = true
        html.destination file("${rootProject.buildDir}/coverage-report")
    }
    def javaClasses = []
    def kotlinClasses = []
    def javaSrc = []
    def kotlinSrc = []
    def execution = []
    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
    rootProject.subprojects.each { proj ->
        javaClasses << fileTree(dir: "$proj.buildDir/intermediates/javac/debug", excludes: fileFilter)
        kotlinClasses << fileTree(dir: "$proj.buildDir/tmp/kotlin-classes/debug", excludes: fileFilter)
        javaSrc << "$proj.projectDir/src/main/java"
        kotlinSrc << "$proj.projectDir/src/main/kotlin"
        execution << fileTree(dir: proj.buildDir, includes: [    'jacoco/testDebugUnitTest.exec',
                'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'])
    }
    getSourceDirectories().setFrom(files([javaSrc, kotlinSrc]))
    getClassDirectories().setFrom(files([javaClasses, kotlinClasses]))
    getExecutionData().setFrom(execution)

    doLast() {
        print "file://${reports.html.destination}/index.html"

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.