Skip to content

Commit 8fe801e

Browse files
authored
Fix Jacoco aggregate report configuration for Gradle 9 (spiffe#387)
* Fix jacocoTestReport configuration for Gradle 9 Configure jacocoClasspath and report output locations explicitly and apply the jacoco plugin at the root project to satisfy Gradle 9 task validation. Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> * Fix error Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com> --------- Signed-off-by: Max Lambrecht <maxlambrecht@gmail.com>
1 parent aef10e2 commit 8fe801e

1 file changed

Lines changed: 27 additions & 23 deletions

File tree

build.gradle

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
id 'jacoco'
23
id 'com.google.osdetector' version '1.7.3'
34
id 'jvm-test-suite'
45
id 'com.vanniktech.maven.publish' version '0.35.0' apply false
@@ -116,40 +117,43 @@ subprojects {
116117
)
117118
}
118119
}
120+
121+
// Disable per-module JaCoCo reports; generate a single aggregate report at root
122+
tasks.withType(JacocoReport).configureEach {
123+
enabled = false
124+
}
119125
}
120126

121127
tasks.register('jacocoTestReport', JacocoReport) {
122-
// Gather execution data from all subprojects
123-
executionData.from(
124-
fileTree(rootDir) {
125-
include '**/build/jacoco/*.exec'
126-
}
127-
)
128+
dependsOn(subprojects.collect { it.tasks.named('test') })
129+
130+
jacocoClasspath = configurations.jacocoAnt
128131

129-
// Add all relevant sourcesets from the subprojects
130-
subprojects.each { p ->
131-
sourceSets p.sourceSets.main
132+
executionData = fileTree(rootDir) {
133+
include '**/build/jacoco/*.exec'
134+
include '**/build/jacoco/*.ec'
132135
}
133136

134-
// Filter out autogenerated or internal code
135-
classDirectories.setFrom(
136-
files(classDirectories.files.collect { dir ->
137-
fileTree(dir: dir, exclude: [
138-
'**/grpc/**',
139-
'**/exception/**',
140-
'**/internal/**'
141-
])
142-
})
143-
)
137+
def mainSourceDirs = files(subprojects.collect { p -> p.sourceSets.main.allSource.srcDirs })
138+
def mainClassDirs = files(subprojects.collect { p -> p.sourceSets.main.output })
139+
140+
sourceDirectories = mainSourceDirs
141+
142+
classDirectories = files(mainClassDirs.files.collect { dir ->
143+
fileTree(dir: dir, exclude: [
144+
'**/grpc/**',
145+
'**/exception/**',
146+
'**/internal/**'
147+
])
148+
})
144149

145150
reports {
146151
xml.required = true
147152
html.required = true
148-
}
149-
}
150153

151-
tasks.named('jacocoTestReport') {
152-
dependsOn(subprojects.collect { it.tasks.named('test') })
154+
xml.outputLocation = layout.buildDirectory.file('reports/jacoco/jacoco.xml')
155+
html.outputLocation = layout.buildDirectory.dir('reports/jacoco/html')
156+
}
153157
}
154158

155159
// copy submodules jars to a common folder for deploy

0 commit comments

Comments
 (0)