11plugins {
2+ `jacoco- report- aggregation`
3+
24 id(" otel.java-conventions" )
35}
46
@@ -9,62 +11,40 @@ dependencies {
911 // Generate aggregate coverage report for published modules that enable jacoco.
1012 subproject.plugins.withId(" jacoco" ) {
1113 subproject.plugins.withId(" maven-publish" ) {
12- implementation(project(subproject.path)) {
13- isTransitive = false
14+ // TODO(anuraaga): Figure out how to avoid transitive dependencies being pulled into jacoco due to the use
15+ // of shadow plugin.
16+ if (subproject.name != " jmx-metrics" ) {
17+ implementation(project(subproject.path)) {
18+ isTransitive = false
19+ }
1420 }
1521 }
1622 }
1723 }
1824}
1925
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- }
26+ afterEvaluate {
27+ tasks {
28+ testCodeCoverageReport {
29+ classDirectories.setFrom(
30+ classDirectories.files.map {
31+ zipTree(it).filter {
32+ // Exclude mrjar (jacoco complains), shaded, and generated code
33+ ! it.absolutePath.contains(" META-INF/versions/" ) &&
34+ ! it.absolutePath.contains(" AutoValue_" )
35+ }
36+ }
37+ )
4538
46- tasks.named<JacocoReport >(" jacocoTestReport" ) {
47- enabled = true
39+ reports {
40+ // xml is usually used to integrate code coverage with
41+ // other tools like SonarQube, Coveralls or Codecov
42+ xml.required.set(true )
4843
49- configurations.runtimeClasspath.get().forEach {
50- additionalClassDirs(
51- zipTree(it).filter {
52- // Exclude mrjar (jacoco complains), shaded, and generated code
53- ! it.absolutePath.contains(" META-INF/versions/" ) &&
54- ! it.absolutePath.contains(" AutoValue_" )
44+ // HTML reports can be used to see code coverage
45+ // without any external tools
46+ html.required.set(true )
5547 }
56- )
57- }
58- additionalSourceDirs(sourcesPath.incoming.artifactView { lenient(true ) }.files)
59- executionData(coverageDataPath.incoming.artifactView { lenient(true ) }.files.filter { it.exists() })
60-
61- reports {
62- // xml is usually used to integrate code coverage with
63- // other tools like SonarQube, Coveralls or Codecov
64- xml.required.set(true )
65-
66- // HTML reports can be used to see code coverage
67- // without any external tools
68- html.required.set(true )
48+ }
6949 }
7050}
0 commit comments