gpt4 book ai didi

java - 具有多个子模块的 Gradle jacoco 覆盖率报告?

转载 作者:搜寻专家 更新时间:2023-11-01 01:32:17 25 4
gpt4 key购买 nike

有谁知道如何为 java jacoco 报告配置 gradle 文件包含多个 gradle 子模块的代码覆盖?

我目前的方法只显示当前子模块的代码覆盖率,但不显示兄弟子模块的代码覆盖。

我有这个项目结构

- build.gradle (1)
- corelib/
- build.gradle (2)
- src/main/java/package/Core.java
- extlib/
- build.gradle (3)
- src/main/java/package/Ext.java
- src/test/java/package/Integrationtest.java

当我执行 gradlew :extlib:check :extlib:jacocoTestReport junit-test "Integrationtest.java"被执行并生成一个代码覆盖率报告,该报告不包含 corelib 类(如 Core.java)的代码覆盖率

结果应该包括Ext.java和Core.java的codecoverage

我读过

却没有发现任何线索

这里是gradle文件的内容

// root build.gradle (1)
// Top-level build file where you can add configuration options
// common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.0'
}
}
allprojects {
repositories {
jcenter()
}
}

// build.gradle (2) subproject build file for corelib.
apply plugin: 'java'
apply plugin: 'jacoco'

dependencies {
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}

// build.gradle (3) subproject build file for extlib.
apply plugin: 'java'
apply plugin: 'jacoco'

dependencies {
compile project(':corelib')
testCompile 'junit:junit:4.11'

// this does not compile
// jacocoTestReport project(':pixymeta-core-lib')
}

jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}

// workaround because android-studio does not make the test resources available
// see https://code.google.com/p/android/issues/detail?id=64887#c13
task copyTestResources(type: Copy) {
from sourceSets.test.resources
into sourceSets.test.output.classesDir
}
processTestResources.dependsOn copyTestResources

[2016-08-01更新]

感谢@Benjamin Muschko,我也尝试了根 gradle 文件

// https://discuss.gradle.org/t/merge-jacoco-coverage-reports-for-multiproject-setups/12100/6
// https://docs.gradle.org/current/dsl/org.gradle.testing.jacoco.tasks.JacocoMerge.html
task jacocoMerge(type: JacocoMerge) {
subprojects.each { subproject ->
executionData subproject.tasks.withType(Test)
}

}

但收到错误消息(使用 gradle-2.14)

* What went wrong:
Some problems were found with the configuration of task ':jacocoMerge'.
> No value has been specified for property 'jacocoClasspath'.
> No value has been specified for property 'executionData'.
> No value has been specified for property 'destinationFile'.

还有 gradle 插件 https://github.com/paveldudka/JacocoEverywhere我在哪里要求多子模块支持 https://github.com/paveldudka/JacocoEverywhere/issues/16

[更新 2016-08-01] 我找到了一个基于 https://github.com/palantir/gradle-jacoco-coverage 的可行解决方案

请看下面我自己的回答

最佳答案

最后我找到了这个插件:https://github.com/palantir/gradle-jacoco-coverage这对我有用:

root gradle.build

buildscript {
repositories {
jcenter()
}
dependencies {
// see https://jcenter.bintray.com/com/android/tools/build/gradle/
classpath 'com.android.tools.build:gradle:2.1.0'
// classpath 'com.android.tools.build:gradle:2.2.0-alpha1'

// https://github.com/palantir/gradle-jacoco-coverage
classpath 'com.palantir:jacoco-coverage:0.4.0'
}
}

// https://github.com/palantir/gradle-jacoco-coverage
apply plugin: 'com.palantir.jacoco-full-report'

具有的所有子项目

apply plugin: 'jacoco'

包含在报告中。

关于java - 具有多个子模块的 Gradle jacoco 覆盖率报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38675853/

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