Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewire Jacoco for Gradle 8/9 #3052

Merged
merged 18 commits into from Jul 8, 2023
Merged
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
63 changes: 30 additions & 33 deletions gradle/root/coverage.gradle
@@ -1,43 +1,25 @@
task mockitoCoverage(type: JacocoReport) {

allprojects { currentProject ->
// These tests do not have a `test` task.
if (currentProject.name in ['android']) {
return
allprojects { project ->
plugins.withId("java") {
project.apply plugin: "jacoco"
project.jacoco {
toolVersion = '0.8.8'
}
szpak marked this conversation as resolved.
Show resolved Hide resolved
plugins.withId("java") {
mockitoCoverage.sourceSets currentProject.sourceSets.main

apply plugin: "jacoco"

jacoco {
toolVersion = '0.8.8'

if (currentProject != rootProject) { //already automatically enhanced in mockito main project as "java" plugin was applied before
applyTo test
}
test.jacoco.destinationFile = file("${currentProject.buildDir}/jacoco/test.exec")
}

mockitoCoverage.executionData(files(test.jacoco.destinationFile).builtBy(test))
}
}

afterEvaluate {
classDirectories.setFrom(
classDirectories.files.collect {
fileTree(
dir: it,
exclude: ["**/internal/util/concurrent/**"]
)
}
)
}
def mockitoCoverage = tasks.register("mockitoCoverage", JacocoReport) { mockitoCoverage ->
allprojects { Project currentProject ->
plugins.withId("jacoco") {
mockitoCoverage.sourceSets currentProject.sourceSets.main
Test test = currentProject.tasks.test
mockitoCoverage.executionData(currentProject.files(test.jacoco.destinationFile).builtBy(test))
}
}

reports {
xml.required = true
html.required = true
html.outputLocation = file("${buildDir}/jacocoHtml")
html.outputLocation = rootProject.layout.buildDirectory.dir("jacocoHtml")
}

doLast {
Expand All @@ -46,4 +28,19 @@ task mockitoCoverage(type: JacocoReport) {
}
}

task coverageReport(dependsOn: ["mockitoCoverage"]) {}
gradle.taskGraph.whenReady {
mockitoCoverage.configure {
classDirectories.setFrom(
TWiStErRob marked this conversation as resolved.
Show resolved Hide resolved
classDirectories.files.collect {
fileTree(
dir: it,
exclude: ["**/internal/util/concurrent/**"]
)
}
)
}
}

tasks.register("coverageReport") {
dependsOn(mockitoCoverage)
}