Skip to content

Commit d6c4d9d

Browse files
authored
Use new jacoco aggregation plugin (#230)
1 parent c4d06b6 commit d6c4d9d

File tree

3 files changed

+29
-98
lines changed

3 files changed

+29
-98
lines changed

all/build.gradle.kts

Lines changed: 28 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
plugins {
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
}

buildSrc/src/main/kotlin/otel.jacoco-conventions.gradle.kts

Lines changed: 0 additions & 49 deletions
This file was deleted.

buildSrc/src/main/kotlin/otel.java-conventions.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import org.gradle.api.tasks.testing.logging.TestExceptionFormat
22

33
plugins {
44
`java-library`
5+
jacoco
56

67
id("otel.errorprone-conventions")
7-
id("otel.jacoco-conventions")
88
id("otel.spotless-conventions")
99
}
1010

0 commit comments

Comments
 (0)