diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-20 13:09:59 +0100 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2021-03-20 14:00:30 +0100 |
| commit | 52467695b1534a8098e8936a3a849c02b2ff98c4 (patch) | |
| tree | 52ec323291fbfe427edd90affb8d0194d01e1990 /simulator/buildSrc/src/main/kotlin | |
| parent | dd24782f3710678151c80f8ad365eecc7389b6f8 (diff) | |
build: Add support for aggregate code coverage results
This change adds support for aggregating code coverage results from the
different modules.
Diffstat (limited to 'simulator/buildSrc/src/main/kotlin')
| -rw-r--r-- | simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts | 26 | ||||
| -rw-r--r-- | simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts | 33 |
2 files changed, 49 insertions, 10 deletions
diff --git a/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts b/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts index 8c07fdea..3e8aa741 100644 --- a/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts +++ b/simulator/buildSrc/src/main/kotlin/jacoco-aggregation.gradle.kts @@ -32,19 +32,25 @@ repositories { mavenCentral() } -task<JacocoReport>("jacocoTestReport") { +tasks.register<JacocoReport>("codeCoverageReport") { group = "Coverage reports" - description = "Generates an aggregate report from all subprojects" + description = "Generates an aggregate report based on all subprojects" - val jacocoReportTasks = subprojects.map { it.tasks.withType<JacocoReport>() } - dependsOn(jacocoReportTasks) - executionData(jacocoReportTasks) + reports { + xml.isEnabled = true + xml.destination = file("${buildDir}/reports/jacoco/report.xml") - subprojects.forEach { testedProject -> - val sourceSets = testedProject.convention.findPlugin(JavaPluginConvention::class)?.sourceSets ?: return@forEach + html.isEnabled = true + } - this@task.additionalSourceDirs.from(sourceSets["main"].allSource.srcDirs) - this@task.sourceDirectories.from(sourceSets["main"].allSource.srcDirs) - this@task.classDirectories.from(sourceSets["main"].output) + subprojects { + this@subprojects.plugins.withType<JacocoPlugin>().configureEach { + this@subprojects.tasks.matching { + it.extensions.findByType<JacocoTaskExtension>() != null } + .configureEach { + sourceSets(this@subprojects.the<SourceSetContainer>().named("main").get()) + executionData(this) + } + } } } diff --git a/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts b/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts index e0bc2ce4..d0534d4f 100644 --- a/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts +++ b/simulator/buildSrc/src/main/kotlin/jacoco-conventions.gradle.kts @@ -30,3 +30,36 @@ tasks.jacocoTestReport { html.isEnabled = true } } + +/* Share sources folder with other projects for aggregated JaCoCo reports */ +configurations.create("transitiveSourcesElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) + } + sourceSets.main.get().java.srcDirs.forEach { + outgoing.artifact(it) + } +} + +/* Share the coverage data to be aggregated for the whole product */ +configurations.create("coverageDataElements") { + isVisible = false + isCanBeResolved = false + isCanBeConsumed = true + extendsFrom(configurations.implementation.get()) + attributes { + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) + } + // This will cause the test task to run if the coverage data is requested by the aggregation task + outgoing.artifact(tasks.test.map { task -> + task.extensions.getByType<JacocoTaskExtension>().destinationFile!! + }) +} |
