This message was deleted.
# kotlin-dsl
s
This message was deleted.
n
Groovy
Copy code
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 = true
        html.outputLocation = layout.buildDirectory.dir("reports/jacoco/html")
        xml.required = true
        xml.outputLocation = layout.buildDirectory.file("reports/jacoco/jacocoFullReport.xml")
    }
}
Kotlin DSL
Copy code
val jacocoFullReport = tasks.register("jacocoFullReport", JacocoReport::class) {
        group = "Reporting"
        description = "Generates an aggregated report from all subprojects"

        val projects = subprojects
            .filter { it.tasks.findByName("jacocoTestDebugUnitTestReport") != null }
            .map { it.tasks.getByName("jacocoTestDebugUnitTestReport", JacocoReport::class) }

        dependsOn(projects)

        val source = files(projects.flatMap { it.sourceDirectories })

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

        classDirectories.setFrom(files(projects.flatMap { it.classDirectories }))

        executionData.setFrom(files(projects.flatMap { it.executionData.files }))

        reports {
            html.required.set(true)
            html.outputLocation.set(layout.buildDirectory.dir("reports/jacoco/html"))
            xml.required.set(true)
            xml.outputLocation.set(layout.buildDirectory.file("reports/jacoco/jacocoFullReport.xml"))
        }
    }
Stacktrace
Copy code
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':jacocoFullReport'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.lambda$executeIfValid$1(ExecuteActionsTaskExecuter.java:149)
... org.gradle.internal.concurrent.AbstractManagedExecutor$1.run(AbstractManagedExecutor.java:47)
Caused by: java.io.IOException: Error while analyzing DataStoreCachedValue$getValue$$inlined$map$1$2.class with JaCoCo 0.8.9.202303310957/c0ad781.
        at org.jacoco.core.analysis.Analyzer.analyzerError(Analyzer.java:163)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:135)
        at org.jacoco.core.analysis.Analyzer.analyzeClass(Analyzer.java:158)
        at org.jacoco.core.analysis.Analyzer.analyzeAll(Analyzer.java:195)
        at org.jacoco.ant.ReportTask.createBundle(ReportTask.java:573)
        at org.jacoco.ant.ReportTask.createReport(ReportTask.java:545)
        at org.jacoco.ant.ReportTask.execute(ReportTask.java:496)
        ... 154 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 13 out of bounds for length 13
v
Things like
java.lang.ArrayIndexOutOfBoundsException: Index 13 out of bounds for length 13
during JaCoCo analysis afair usually come when your Java version is newer than what your JaCoCo version supports. It is very unlikely that this is caused by Kotlin DSL vs. Groovy DSL. But besides that, you really should not do such unsafe reaching into project model and results of other projects. To learn how to properly and safely share things between projects, have a look at https://docs.gradle.org/current/userguide/cross_project_publications.html. And especially for your case, just use https://docs.gradle.org/current/userguide/jacoco_report_aggregation_plugin.html which uses exactly these techniques to provide aggregated reports.
n
Thanks for the answer! Since I am on Android, The JaCoCo Report Aggregation Plugin still doesn’t support it AFAIK 😕
v
Oh, I see, yeah at least according to its documentation. But I guess you should just do the same it does, only adapted to Android. You can probably actually half-use it I guess. I just today used it to generate an aggregate report across unit- and functional test suite which it does not support out of the box by creating another consumable configuration to which I attach the jacoco result files and for which I then configured a report the plugin then makes a task off. Worked like a breeze.
n
Thank you, I will look into aggregation API for sure. BTW my problem was JaCoCo version.
0.8.11
breaks but
0.8.9
works