Gradle jacoco覆盖报告包含多个子模块?

有谁知道如何为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:jacocoTestReportjunit-test“

Integrationtest.java”并执行代码生成报告时,该报告不包含Corelib类(如Core.java)的代码覆盖

结果应包括Ext.java和Core.java的代码覆盖率

我已经看过

  • https://docs.gradle.org/current/userguide/jacoco_plugin.html

但没有发现任何线索

这是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为我完成了这项工作:

根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'

包含在报告中。

以上是 Gradle jacoco覆盖报告包含多个子模块? 的全部内容, 来源链接: utcz.com/qa/400576.html

回到顶部