|
| 1 | +plugins { |
| 2 | + id("otel.java-conventions") |
| 3 | +} |
| 4 | + |
| 5 | +description = "OpenTelemetry Contrib Testing" |
| 6 | + |
| 7 | +dependencies { |
| 8 | + rootProject.subprojects.forEach { subproject -> |
| 9 | + // Generate aggregate coverage report for published modules that enable jacoco. |
| 10 | + subproject.plugins.withId("jacoco") { |
| 11 | + subproject.plugins.withId("maven-publish") { |
| 12 | + implementation(project(subproject.path)) { |
| 13 | + isTransitive = false |
| 14 | + } |
| 15 | + } |
| 16 | + } |
| 17 | + } |
| 18 | +} |
| 19 | + |
| 20 | +// https://docs.gradle.org/current/samples/sample_jvm_multi_project_with_code_coverage.html |
| 21 | + |
| 22 | +val sourcesPath by configurations.creating { |
| 23 | + isVisible = false |
| 24 | + isCanBeResolved = true |
| 25 | + isCanBeConsumed = false |
| 26 | + extendsFrom(configurations.implementation.get()) |
| 27 | + attributes { |
| 28 | + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) |
| 29 | + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) |
| 30 | + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +val coverageDataPath by configurations.creating { |
| 35 | + isVisible = false |
| 36 | + isCanBeResolved = true |
| 37 | + isCanBeConsumed = false |
| 38 | + extendsFrom(configurations.implementation.get()) |
| 39 | + attributes { |
| 40 | + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) |
| 41 | + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) |
| 42 | + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) |
| 43 | + } |
| 44 | +} |
| 45 | + |
| 46 | +tasks.named<JacocoReport>("jacocoTestReport") { |
| 47 | + enabled = true |
| 48 | + |
| 49 | + configurations.runtimeClasspath.get().forEach { |
| 50 | + additionalClassDirs(zipTree(it).filter { |
| 51 | + // Exclude mrjar (jacoco complains), shaded, and generated code |
| 52 | + !it.absolutePath.contains("META-INF/versions/") && |
| 53 | + !it.absolutePath.contains("AutoValue_") |
| 54 | + }) |
| 55 | + } |
| 56 | + additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) |
| 57 | + executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) |
| 58 | + |
| 59 | + reports { |
| 60 | + // xml is usually used to integrate code coverage with |
| 61 | + // other tools like SonarQube, Coveralls or Codecov |
| 62 | + xml.required.set(true) |
| 63 | + |
| 64 | + // HTML reports can be used to see code coverage |
| 65 | + // without any external tools |
| 66 | + html.required.set(true) |
| 67 | + } |
| 68 | +} |
0 commit comments