plugins {
    base
    jacoco
}

repositories {
    mavenCentral()
}

dependencies {
}

val jacocoTestReport = tasks.register<JacocoReport>("jacocoTestReport") {
    group = "Verification"
    description = "Generates a consolidated JaCoCo report for all subprojects."

    val javaSubprojects = subprojects.filter { subproject ->
        subproject.subprojects.isEmpty() && subproject.plugins.hasPlugin("java")
    }

    dependsOn(javaSubprojects.map { it.tasks.withType<JacocoReport>() })

    additionalSourceDirs.setFrom(javaSubprojects.map { it.layout.projectDirectory.dir("src/main/java") })
    sourceDirectories.setFrom(javaSubprojects.map { it.layout.projectDirectory.dir("src/main/java") })
    classDirectories.setFrom(javaSubprojects.map { it.layout.buildDirectory.dir("classes/java/main") })
    executionData.setFrom(fileTree(projectDir).include("**/build/jacoco/*.exec"))

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