https://kotlinlang.org logo
#gradle
Title
# gradle
n

nuhkoca

06/25/2022, 1:39 PM
Hello, I have a
jacocoTestReport
task that depends on
testDebugUnitTest
and it was just generating
debug
related reports and exec files but since the last week
jacocoTestReport
both executes
debug
,
internal
and
release
tasks and generates reports. This has drastically increased CI time. I never touched configuration or so. What could be the root cause to this misconduct?
message has been deleted
jacoco.gradle
Copy code
apply plugin: 'jacoco'

tasks.withType(Test) {
    jacoco.includeNoLocationClasses true
    // see related issue <https://github.com/gradle/gradle/issues/5184#issuecomment-457865951>
    jacoco.excludes = ['jdk.internal.*']
}

afterEvaluate { project ->
    if (isModuleExcluded(project)) {
        println "Jacoco: Ignoring $name module for coverage"
        return false
    }

    if (isAndroidModule(project)) setupAndroidReporting()
    else setupKotlinReporting()
}

private def setupKotlinReporting() {
    jacocoTestReport {
        dependsOn test

        reports {
            html.required.set(true)
            xml.required.set(true)
        }
    }
}

private def setupAndroidReporting() {
    task jacocoTestReport(type: JacocoReport, dependsOn: 'testDebugUnitTest') {
        group = "Reporting"
        description = "Generate Jacoco coverage reports for the debug build"

        reports {
            html.required.set(true)
            xml.required.set(true)
        }

        def javaTree = fileTree(
                dir: "$buildDir/intermediates/javac/debug",
                excludes: coverageExcludes
        )
        def kotlinTree = fileTree(
                dir: "$buildDir/tmp/kotlin-classes/debug",
                excludes: coverageExcludes
        )
        classDirectories.setFrom(files([javaTree, kotlinTree]))

        def coverageSourceDirs = [
                "$projectDir/src/main/java",
                "$projectDir/src/main/kotlin"
        ]
        sourceDirectories.setFrom(files(coverageSourceDirs))

        executionData.setFrom(files("$buildDir/jacoco/testDebugUnitTest.exec"))
    }
}
coverage.gradle
Copy code
apply from: "buildsystem/quality/coverage/coverage-config.gradle"
apply from: "buildsystem/quality/coverage/sonar.gradle"

apply plugin: 'jacoco'

subprojects { project ->
    project.apply from: "../buildsystem/quality/coverage/jacoco.gradle"
}

def jacocoFullReport = tasks.register("jacocoFullReport", JacocoReport) {
    group = 'Reporting'
    description = 'Generates an aggregated report from all subprojects'

    def projects = subprojects.findAll { project -> !isModuleExcluded(project) }

    dependsOn(projects.jacocoTestReport)

    final source = files(projects.jacocoTestReport.sourceDirectories)

    additionalSourceDirs.setFrom(source)
    sourceDirectories.setFrom(source)

    classDirectories.setFrom(files(projects.jacocoTestReport.classDirectories))
    executionData.setFrom(files(projects.jacocoTestReport.executionData))

    reports {
        html.required.set(true)
        html.outputLocation.set(file("$buildDir/reports/jacoco/html"))
        xml.required.set(true)
        xml.outputLocation.set(file("$buildDir/reports/jacoco/jacocoFullReport.xml"))
    }
}

tasks.sonarqube.dependsOn jacocoFullReport
Hmm beforehand, there was only one
jacocoTestReport
task created by me but now there are 3 others created by something else 🤔 Has something changed with Gradle’s latest version?
Ok apparently, JUnit5 plugin also adds some Jacoco tasks and causes this issue
138 Views