Jacoco 报告聚合插件未生成 XML 文件

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

我正在开发一个多模块项目,该项目使用一个独立的子项目来汇总覆盖率报告。该项目是使用 Gradle 构建的,因此它使用 Gradle 的Jacoco 报告聚合插件

目前,覆盖率报告仅以 HTML 格式生成。但是,我特别需要 XML 文件格式,以便我可以将其合并到 Azure DevOps 管道中的工件中。

根项目和子项目有以下

build.grade
配置文件:

根项目

plugins {
    id 'java'
}   
sourceCompatibility = '17'
allprojects {
    repositories {
        mavenCentral()
    }    
    tasks.withType(Test.class).tap {
        configureEach {
            useJUnitPlatform()
        }
    }
}

子项目之一

plugins {
    id 'java'
    id 'jacoco'
}
dependencies {
   ...
}

独立覆盖子项目

 plugins {
   id 'java'     
   id 'jacoco-report-aggregation'
}
bootJar {
    enabled = false
}
jar {
    enabled = false
}    
dependencies {
    jacocoAggregation project(':sub-project1')
    jacocoAggregation project(':sub-project2')  
  }

要生成报告,我使用以下 Gradle 命令:

> gradle clean build jacocoTestReport 

在没有子项目的不同项目中,我能够通过配置 Jacoco 插件报告来生成 XML 文件,如下所示:

构建.等级

jacocoTestReport {
  reports {
    xml.required = true
    csv.required = false
}   

但是到目前为止,我还无法为多模块项目生成 XML 格式。

任何建议或线索都将不胜感激。

java gradle code-coverage jacoco jacoco-plugin
1个回答
0
投票

解决方案位于 Gradle 官方网站的示例中。

根项目和子项目

gradle.settigns
文件在我的问题中是正确的。 但对于覆盖项目,
gradle.settings
缺少依赖项 妓女文件应该是:

plugins {
   id 'java'     
   id 'jacoco-report-aggregation'
}
bootJar {
    enabled = false
}
jar {
    enabled = false
}    
dependencies {
    jacocoAggregation project(':sub-project1')
    jacocoAggregation project(':sub-project2')  
}
//as in sample for the case you want to build the report when you run check
tasks.named('check') {
    dependsOn tasks.named('testCodeCoverageReport', JacocoReport)
}

要生成汇总报告,命令行应为:

$ ./gradlew testCodeCoverageReport //Invoke task `jacocoTestReport`  will not build the aggregate report as I was doing.

报告将在

<coverage project path>/build/reports/jacoco/testCodeCoverageReport
生成。

XML 文件也会在那里生成。

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