apply plugin: 'kotlin'
apply plugin: 'jacoco'

jacoco {
    toolVersion = "$jacoco_tool_version"
}

def jacocoProjects = (jacocoMulti.jacocoProjects)
def jacocoSourceProjects = (jacocoMulti.sourceProjects)

task jacocoMerge(type: JacocoMerge) {
    jacocoProjects.each {
        executionData file("${it.buildDir}/jacoco").listFiles().findAll { it.name.endsWith(".exec") }
    }
}

task codeCoverageReport(type: JacocoReport) {

    dependsOn jacocoMulti.sourceProjects.build
    dependsOn jacocoMerge
    jacocoMerge.mustRunAfter jacocoMulti.sourceProjects.build

    executionData jacocoMerge.destinationFile

    jacocoSourceProjects.each {
        sourceSets it.sourceSets.main
    }

    doFirst {
        println "going to generate merged jacoco report based on:"
        println "  - source projects: ${jacocoSourceProjects*.name}"
        println "  - jacoco projects: ${jacocoProjects*.name}"
        println "========================================="
    }

    reports {
        xml.enabled = true
        xml.destination file("${buildDir}/reports/jacoco/report.xml")
        html.enabled = true
        html.destination file("${buildDir}/reports/jacoco/html/")
        csv.enabled = false
    }
}
