Skip to content

Commit 3457d42

Browse files
committed
Replace Jacoco with Kover for code coverage reporting
1 parent 3288f3a commit 3457d42

3 files changed

Lines changed: 5 additions & 119 deletions

File tree

document-manager/build.gradle.kts

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ plugins {
3030
alias(libs.plugins.dependencycheck)
3131
alias(libs.plugins.sonarqube)
3232
alias(libs.plugins.maven.publish)
33-
jacoco
34-
}
35-
36-
jacoco {
37-
toolVersion = libs.versions.jacoco.get()
33+
alias(libs.plugins.kover)
3834
}
3935

4036
val NAMESPACE: String by project
@@ -93,13 +89,6 @@ android {
9389
}
9490
}
9591

96-
// Register Jacoco tasks for each variant
97-
androidComponents {
98-
onVariants { variant ->
99-
createJacocoTasks(variant.name)
100-
}
101-
}
102-
10392
kotlinOptions {
10493
jvmTarget = libs.versions.java.get()
10594
freeCompilerArgs += listOf(
@@ -236,111 +225,7 @@ afterEvaluate {
236225
}
237226
}
238227

239-
// Jacoco Tasks
240-
241-
val coverageExclusions = listOf(
242-
"**/databinding/*Binding.*",
243-
"**/R.class",
244-
"**/R$*.class",
245-
"**/BuildConfig.*",
246-
"**/Manifest*.*",
247-
"**/*Test*.*",
248-
"android/**/*.*",
249-
// butterKnife
250-
"**/*\$ViewInjector*.*",
251-
"**/*\$ViewBinder*.*",
252-
"**/Lambda\$*.class",
253-
"**/Lambda.class",
254-
"**/*Lambda.class",
255-
"**/*Lambda*.class",
256-
"**/*_MembersInjector.class",
257-
"**/Dagger*Component*.*",
258-
"**/*Module_*Factory.class",
259-
"**/di/module/*",
260-
"**/*_Factory*.*",
261-
"**/*Module*.*",
262-
"**/*Dagger*.*",
263-
"**/*Hilt*.*",
264-
// kotlin
265-
"**/*MapperImpl*.*",
266-
"**/*\$ViewInjector*.*",
267-
"**/*\$ViewBinder*.*",
268-
"**/BuildConfig.*",
269-
"**/*Component*.*",
270-
"**/*BR*.*",
271-
"**/Manifest*.*",
272-
"**/*\$Lambda\$*.*",
273-
"**/*Companion*.*",
274-
"**/*Module*.*",
275-
"**/*Dagger*.*",
276-
"**/*Hilt*.*",
277-
"**/*MembersInjector*.*",
278-
"**/*_MembersInjector.class",
279-
"**/*_Factory*.*",
280-
"**/*_Provide*Factory*.*",
281-
"**/*Extensions*.*"
282-
)
228+
283229

284230
fun String.capitalize() =
285231
replaceFirstChar { if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }
286-
287-
fun createJacocoTasks(variantName: String) {
288-
val testTaskName = "test${variantName.capitalize()}UnitTest"
289-
val taskName = "${testTaskName}Coverage"
290-
val javaClasses = layout.buildDirectory.dir("intermediates/javac/${variantName}")
291-
.get().asFileTree.matching {
292-
exclude(coverageExclusions)
293-
}
294-
val kotlinClasses = layout.buildDirectory.dir("tmp/kotlin-classes/${variantName}")
295-
.get().asFileTree.matching {
296-
exclude(coverageExclusions)
297-
}
298-
val sourceDirs = files(
299-
"$projectDir/src/main/java",
300-
"$projectDir/src/main/kotlin",
301-
"$projectDir/src/${variantName}/java",
302-
"$projectDir/src/${variantName}/kotlin"
303-
)
304-
val executionDataVariant =
305-
layout.buildDirectory.file("/outputs/unit_test_code_coverage/${variantName}UnitTest/${testTaskName}.exec")
306-
.get().asFile
307-
308-
val reportTask = tasks.register<JacocoReport>(taskName) {
309-
group = "reporting"
310-
description = "Generate Jacoco coverage reports for the $variantName build."
311-
dependsOn(testTaskName)
312-
reports {
313-
xml.required = true
314-
html.required = true
315-
}
316-
sourceDirectories.setFrom(sourceDirs)
317-
classDirectories.setFrom(javaClasses, kotlinClasses)
318-
executionData.setFrom(executionDataVariant)
319-
320-
doLast {
321-
layout.buildDirectory.file("reports/jacoco/${taskName}/html/index.html")
322-
.get()
323-
.asFile
324-
.readText()
325-
.let { Regex("Total[^%]*>(\\d?\\d?\\d?%)").find(it) }
326-
?.let { println("Test coverage: ${it.groupValues[1]}") }
327-
}
328-
}
329-
tasks.register<JacocoCoverageVerification>("${testTaskName}CoverageVerification") {
330-
group = "reporting"
331-
description = "Verifies Jacoco coverage for the $variantName build."
332-
dependsOn(reportTask.name)
333-
334-
violationRules {
335-
rule {
336-
limit {
337-
minimum = 80.toBigDecimal()
338-
}
339-
}
340-
}
341-
342-
classDirectories.setFrom(kotlinClasses, javaClasses)
343-
sourceDirectories.setFrom(sourceDirs)
344-
executionData.setFrom("${layout.buildDirectory.get()}$executionDataVariant")
345-
}
346-
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ android.nonTransitiveRClass=true
4040

4141
systemProp.sonar.host.url=https://sonarcloud.io
4242
systemProp.sonar.gradle.skipCompile=true
43-
systemProp.sonar.coverage.jacoco.xmlReportPaths=build/reports/jacoco/testDebugUnitTestCoverage/testDebugUnitTestCoverage.xml,build/reports/jacoco/testReleaseUnitTestCoverage/testReleaseUnitTestCoverage.xml
43+
systemProp.sonar.coverage.reportPaths=build/reports/kover/xml/report.xml
4444
systemProp.sonar.projectName=eudi-lib-android-wallet-document-manager
4545
VERSION_NAME=0.12.1-SNAPSHOT
4646

gradle/libs.versions.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ cose = "1.1.0"
66
dependency-license-report = "2.9"
77
dependencycheck = "12.1.3"
88
dokka = "1.9.20"
9-
jacoco = "0.8.12"
109
java = "17"
1110
json = "20250517"
1211
kotlin = "2.1.21"
@@ -20,6 +19,7 @@ sonarqube = "6.2.0.5505"
2019
eudi-sd-jwt-vc-kt = "0.10.0"
2120
nimbus = "9.47"
2221
ktor = "3.3.0"
22+
kover = "0.9.1"
2323

2424
[libraries]
2525
bouncy-castle-pkix = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bouncy-castle" }
@@ -50,3 +50,4 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
5050
maven-publish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" }
5151
sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" }
5252
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
53+
kover = { id = "org.jetbrains.kotlinx.kover", version.ref = "kover" }

0 commit comments

Comments
 (0)