Not able to generate Jacoco reports in Java multi module project

300 views Asked by At

I'm working on a Java Spring Boot project using Gradle 7.5

It is organized in multiple modules, which most of them have some tests included.

Today I've tried to enable code coverage reports for my project. Therefore I've added the jacoco plugin to allprojects:

`

apply plugin: 'jacoco'

jacoco {
    toolVersion = "0.8.8"
}

`

On subprojects I've the following task:

`

jacocoTestReport {
    reports {
        html.enabled = true
        xml.enabled = true
        csv.enabled = false
    }
}

` When I try to run the task jacocoTestReport the build fails and following error is shown on the first module:

The value for this file collection is final and cannot be changed

What I'm doing wrong here?

Thanks for your help!

I've already tried different versions of gradle and googled a lot, but unfortunately, none of the proposed soltions worked for me.

1

There are 1 answers

0
Dehong Liang On

I have also encountered this problem, and I still don't know how to solve it.

jdk Version:11

gradle Version:7.5

jacoco.gradle Part of the code is as follows:

task jacocoTotalReport(type: JacocoReport, dependsOn: project.getTasksByName("testDebugUnitTest", true)) {
    doFirst {
        subprojects.each { project ->
           
            def unitTestResultFile = "${project.buildDir}/jacoco/testDebugUnitTest.exec"

            if (file(unitTestResultFile).exists() && executionData != null) {
                executionData.setFrom(unitTestResultFile)
            }
        }
    }
}


Error content:
> The value for this file collection is final and cannot be changed.