|
| 1 | +plugins { |
| 2 | + `java-library` |
| 3 | +} |
| 4 | + |
| 5 | +description = "AWS X-Ray SDK Code Coverage" |
| 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 | +val sourcesPath by configurations.creating { |
| 21 | + isVisible = false |
| 22 | + isCanBeResolved = true |
| 23 | + isCanBeConsumed = false |
| 24 | + extendsFrom(configurations.implementation.get()) |
| 25 | + attributes { |
| 26 | + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) |
| 27 | + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) |
| 28 | + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("source-folders")) |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +val coverageDataPath by configurations.creating { |
| 33 | + isVisible = false |
| 34 | + isCanBeResolved = true |
| 35 | + isCanBeConsumed = false |
| 36 | + extendsFrom(configurations.implementation.get()) |
| 37 | + attributes { |
| 38 | + attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME)) |
| 39 | + attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.DOCUMENTATION)) |
| 40 | + attribute(DocsType.DOCS_TYPE_ATTRIBUTE, objects.named("jacoco-coverage-data")) |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +// Task to gather code coverage from multiple subprojects |
| 45 | +val codeCoverageReport by tasks.registering(JacocoReport::class) { |
| 46 | + additionalClassDirs(configurations.runtimeClasspath.get()) |
| 47 | + additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true) }.files) |
| 48 | + executionData(coverageDataPath.incoming.artifactView { lenient(true) }.files.filter { it.exists() }) |
| 49 | + |
| 50 | + reports { |
| 51 | + // xml is usually used to integrate code coverage with |
| 52 | + // other tools like SonarQube, Coveralls or Codecov |
| 53 | + xml.isEnabled = true |
| 54 | + |
| 55 | + // HTML reports can be used to see code coverage |
| 56 | + // without any external tools |
| 57 | + html.isEnabled = true |
| 58 | + } |
| 59 | +} |
| 60 | + |
0 commit comments