How to make “sourceDirectories” public in Jacoco report generation?

久未见 提交于 2021-02-16 20:32:10

问题


I was following this post to setup Jacoco code coverage for my project.

But I am facing a error while writing the task to generate the report.

Gradle Task

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

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

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
    def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter)
    def mainSrc = "$project.projectDir/src/main/java"

    sourceDirectories = files([mainSrc])
    classDirectories = files([debugTree])
    executionData = fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec', 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'
    ])
}

The error I am getting is :

Cannot set the value of read-only property 'sourceDirectories' for task ':app:jacocoTestReport' of type org.gradle.testing.jacoco.tasks.JacocoReport.

Below field's are private in the jacoco now I believe.

  • sourceDirectories
  • classDirectories
  • executionData

My dependency : classpath "org.jacoco:org.jacoco.core:0.8.4"

Also, I tried to change the version but no help.


回答1:


Found the Answer here

task jacocoTestReport(type: JacocoReport, dependsOn: ['testDebugUnitTest', 'createDebugCoverageReport']) {

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

    def fileFilter = ['**/R.class', '**/R$*.class', '**/BuildConfig.*', '**/Manifest*.*', '**/*Test*.*', 'android/**/*.*']
    def debugTree = fileTree(dir: "$project.buildDir/intermediates/javac/debug", excludes: fileFilter)
    def mainSrc = "$project.projectDir/src/main/java"

    sourceDirectories.from files([mainSrc])
    classDirectories.from files([debugTree])
    executionData.from fileTree(dir: project.buildDir, includes: [
            'jacoco/testDebugUnitTest.exec', 'outputs/code_coverage/debugAndroidTest/connected/**/*.ec'
    ])
}

(sourceDirectories =) in not allowed in latest gradle version instead (sourceDirectories.from) should be used .



来源:https://stackoverflow.com/questions/62740456/how-to-make-sourcedirectories-public-in-jacoco-report-generation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!