Skip to content

Commit 90a26cb

Browse files
committed
ci: update jacoco configuration
1 parent 84112c1 commit 90a26cb

9 files changed

Lines changed: 213 additions & 18 deletions

File tree

aggregates/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ plugins {
77
alias(libs.plugins.kotlin.compose.compiler)
88
}
99

10+
apply(from = "${project.rootDir}/jacoco/jacoco-kmp.gradle.kts")
11+
1012
kotlin {
1113
androidTarget {
1214
compilerOptions {

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ allprojects {
5858
cacheChangingModulesFor(0, TimeUnit.SECONDS)
5959
eachDependency {
6060
if (requested.group == "org.jacoco")
61-
useVersion("0.8.10")
61+
useVersion(libs.versions.jacoco.get())
6262
}
6363
}
6464
}

commonskmm/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ plugins {
1212
alias(libs.plugins.kotlin.serialization)
1313
}
1414

15+
apply(from = "${project.rootDir}/jacoco/jacoco-kmp.gradle.kts")
16+
1517
kotlin {
1618
compilerOptions {
1719
freeCompilerArgs.add("-Xcontext-parameters")

gradle/verification-metadata.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9808,6 +9808,14 @@
98089808
<sha256 value="f038f5d61e0a6ba319b05073b284a15c86bb7747e4a3496b27f37a71180b1cd7" origin="Generated by Gradle"/>
98099809
</artifact>
98109810
</component>
9811+
<component group="org.jacoco" name="org.jacoco.agent" version="0.8.14">
9812+
<artifact name="org.jacoco.agent-0.8.14.jar">
9813+
<sha256 value="20be9853385bdfc65a5929643412d09243d14514304b89ba23a265158cc8792b" origin="Generated by Gradle"/>
9814+
</artifact>
9815+
<artifact name="org.jacoco.agent-0.8.14.pom">
9816+
<sha256 value="943e77ed5ccb99aeeb3fe5643fea5a636f6f828e3958f8605f426ddc9afab8c9" origin="Generated by Gradle"/>
9817+
</artifact>
9818+
</component>
98119819
<component group="org.jacoco" name="org.jacoco.ant" version="0.8.10">
98129820
<artifact name="org.jacoco.ant-0.8.10.jar">
98139821
<sha256 value="a7c8dd6741acb337cc0771a9bf176aa67c09a52a6de011eb7a0f5e78c9bd5872" origin="Generated by Gradle"/>
@@ -9816,6 +9824,14 @@
98169824
<sha256 value="f09f765b3f0deb5cda941486d6be25752f97842e3fe325537d69e81bbc137b2f" origin="Generated by Gradle"/>
98179825
</artifact>
98189826
</component>
9827+
<component group="org.jacoco" name="org.jacoco.ant" version="0.8.14">
9828+
<artifact name="org.jacoco.ant-0.8.14.jar">
9829+
<sha256 value="9fff68954d5de3aad2bf838eaf886ed67d2c22a2d6c6f095548bade8c45caeae" origin="Generated by Gradle"/>
9830+
</artifact>
9831+
<artifact name="org.jacoco.ant-0.8.14.pom">
9832+
<sha256 value="2fc8e4b542163feef345eb59e898bcebdee16f65df40303032d92062427b15a5" origin="Generated by Gradle"/>
9833+
</artifact>
9834+
</component>
98199835
<component group="org.jacoco" name="org.jacoco.build" version="0.8.10">
98209836
<artifact name="org.jacoco.build-0.8.10.pom">
98219837
<sha256 value="e3d7b0d98debaa1453393c2203819212c5287ebbc467dd0b4a22ad0466bd6c3b" origin="Generated by Gradle"/>
@@ -9850,6 +9866,14 @@
98509866
<sha256 value="6a85b036ab875758efde0f98df410086e9b9d57d826188a8b14560542df2bae2" origin="Generated by Gradle"/>
98519867
</artifact>
98529868
</component>
9869+
<component group="org.jacoco" name="org.jacoco.report" version="0.8.14">
9870+
<artifact name="org.jacoco.report-0.8.14.jar">
9871+
<sha256 value="a3e2026060ab8b8d5c650706406234bb4c033dfd5376afeb8b1666e8ed27c453" origin="Generated by Gradle"/>
9872+
</artifact>
9873+
<artifact name="org.jacoco.report-0.8.14.pom">
9874+
<sha256 value="e2ebf2c580f86afa7f75f43a28109dd894c42463928bc9911777e35275108e58" origin="Generated by Gradle"/>
9875+
</artifact>
9876+
</component>
98539877
<component group="org.jdom" name="jdom2" version="2.0.6">
98549878
<artifact name="jdom2-2.0.6.jar">
98559879
<sha256 value="1345f11ba606d15603d6740551a8c21947c0215640770ec67271fe78bea97cf5" origin="Generated by Gradle"/>

jacoco/jacoco-kmp.gradle.kts

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
apply(plugin = "jacoco")
2+
3+
// Check if this is a Kotlin Multiplatform project
4+
val isKmpProject = plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")
5+
val isAndroidProject = plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application")
6+
7+
tasks.register("jacocoReport", JacocoReport::class) {
8+
group = "Coverage"
9+
description = "Generate XML/HTML code coverage reports"
10+
11+
// Set source directories based on project type
12+
if (isKmpProject) {
13+
// For KMP projects, include all source sets
14+
sourceDirectories.setFrom(
15+
layout.projectDirectory.dir("src/commonMain/kotlin"),
16+
layout.projectDirectory.dir("src/androidMain/kotlin"),
17+
layout.projectDirectory.dir("src/commonTest/kotlin"),
18+
layout.projectDirectory.dir("src/androidUnitTest/kotlin")
19+
)
20+
} else {
21+
// For Android projects
22+
sourceDirectories.setFrom("${project.projectDir}/src/main/java")
23+
}
24+
25+
val excludes = mutableSetOf<String>(
26+
"android/databinding/**/*.class",
27+
"**/android/databinding/*Binding.class",
28+
"**/android/databinding/*",
29+
"**/androidx/databinding/*",
30+
"**/BR.*",
31+
"**/R.class",
32+
"**/R\$*.class",
33+
"**/BuildConfig.*",
34+
"**/Manifest*.*",
35+
"**/*Test*.*",
36+
"android/**/*.*",
37+
"**/*MapperImpl*.*",
38+
"**/*\$ViewInjector*.*",
39+
"**/*\$ViewBinder*.*",
40+
"**/BuildConfig.*",
41+
"**/*Component*.*",
42+
"**/*BR*.*",
43+
"**/Manifest*.*",
44+
"**/*\$Lambda\$*.*",
45+
"**/*Companion*.*",
46+
"**/*Module*.*",
47+
"**/*Dagger*.*",
48+
"**/*MembersInjector*.*",
49+
"**/*_MembersInjector.class",
50+
"**/*_Factory*.*",
51+
"**/*_Provide*Factory*.*",
52+
"**/*Extensions*.*",
53+
"**/*\$Result.*",
54+
"**/*\$Result\$*.*",
55+
"**/*JsonAdapter.*",
56+
"**/databinding/*.*",
57+
"**/customviews/*.*",
58+
"**/ui/*.class",
59+
"**/*Activity.*",
60+
"**/Activity*.*",
61+
"**/*Activity*.*",
62+
"**/*Fragment.*",
63+
"**/Fragment*.*",
64+
"**/*View.*",
65+
"**/*Adapter.*",
66+
"**/*Contract*.*",
67+
"**/*Bindings*.*",
68+
"**/AutoValue*.*",
69+
"**/*\$*",
70+
"**/*Navigator.*",
71+
"**/*\$*\$*.*",
72+
"**/animations/*.*",
73+
"**/*Holder*.*",
74+
"**/*Dialog*.*",
75+
"**/*Service*.*",
76+
"**/*Button*.*",
77+
"**/SearchTEList.*",
78+
"**/lambda\$*\$*.*"
79+
)
80+
81+
// Set class directories based on project type
82+
val classDirectoriesList = mutableListOf<Any>()
83+
84+
if (isAndroidProject) {
85+
// Android project class directories
86+
val javaClassesApp = fileTree(layout.buildDirectory.dir("intermediates/javac/dhisDebug")){
87+
exclude(excludes)
88+
}
89+
val kotlinClassesApp = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/dhisDebug")){
90+
exclude(excludes)
91+
}
92+
val javaClasses = fileTree(layout.buildDirectory.dir("intermediates/javac/debug")){
93+
exclude(excludes)
94+
}
95+
val kotlinClasses = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/debug")){
96+
exclude(excludes)
97+
}
98+
99+
classDirectoriesList.addAll(listOf(javaClassesApp, kotlinClassesApp, javaClasses, kotlinClasses))
100+
}
101+
102+
if (isKmpProject) {
103+
// KMP project class directories
104+
val commonClasses = fileTree(layout.buildDirectory.dir("classes/kotlin/common")){
105+
exclude(excludes)
106+
}
107+
val androidClasses = fileTree(layout.buildDirectory.dir("classes/kotlin/android")){
108+
exclude(excludes)
109+
}
110+
val jvmClasses = fileTree(layout.buildDirectory.dir("classes/kotlin/jvm")){
111+
exclude(excludes)
112+
}
113+
114+
classDirectoriesList.addAll(listOf(commonClasses, androidClasses, jvmClasses))
115+
}
116+
117+
classDirectories.setFrom(files(classDirectoriesList))
118+
119+
// Execution data - look for both .exec and .ec files
120+
val unitTestsData = fileTree(layout.buildDirectory.dir("jacoco")) {
121+
include("*.exec")
122+
}
123+
val androidTestsData = fileTree(layout.buildDirectory.dir("outputs/code_coverage")) {
124+
include(listOf("**/*.ec"))
125+
}
126+
127+
executionData.setFrom(files(listOf(unitTestsData, androidTestsData)))
128+
129+
// Add test task dependencies based on project type
130+
if (isAndroidProject) {
131+
val testTask = tasks.findByName("testDebugUnitTest")
132+
val androidTestTask = tasks.findByName("connectedDebugAndroidTest")
133+
134+
if (testTask != null) dependsOn(testTask)
135+
if (androidTestTask != null) dependsOn(androidTestTask)
136+
}
137+
138+
if (isKmpProject) {
139+
val commonTestTask = tasks.findByName("test")
140+
val androidTestTask = tasks.findByName("androidTest")
141+
142+
if (commonTestTask != null) dependsOn(commonTestTask)
143+
if (androidTestTask != null) dependsOn(androidTestTask)
144+
}
145+
146+
fun JacocoReportsContainer.reports() {
147+
xml.required.set(true)
148+
xml.outputLocation.set(layout.buildDirectory.file("coverage-report/jacocoTestReport.xml"))
149+
150+
html.required.set(true)
151+
html.outputLocation.set(layout.buildDirectory.dir("coverage-report"))
152+
}
153+
154+
reports {
155+
reports()
156+
}
157+
}

jacoco/jacoco.gradle.kts

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ tasks.register("jacocoReport", JacocoReport::class) {
44
group = "Coverage"
55
description = "Generate XML/HTML code coverage reports for coverage.ec"
66

7+
// Make sure tests are run before generating the report
8+
// Only add dependencies if the tasks exist
9+
val testTask = tasks.findByName("testDebugUnitTest")
10+
val androidTestTask = tasks.findByName("connectedDebugAndroidTest")
11+
12+
if (testTask != null) {
13+
dependsOn(testTask)
14+
}
15+
if (androidTestTask != null) {
16+
dependsOn(androidTestTask)
17+
}
18+
719
sourceDirectories.setFrom("${project.projectDir}/src/main/java")
820

921
val excludes = mutableSetOf<String>(
@@ -62,18 +74,18 @@ tasks.register("jacocoReport", JacocoReport::class) {
6274
"**/lambda\$*\$*.*"
6375
)
6476

65-
val javaClassesApp = fileTree("${buildDir}/intermediates/javac/dhisDebug"){
77+
val javaClassesApp = fileTree(layout.buildDirectory.dir("intermediates/javac/dhisDebug")){
6678
exclude(
6779
excludes
6880
)
6981
}
70-
val kotlinClassesApp = fileTree("${buildDir}/tmp/kotlin-classes/dhisDebug"){
82+
val kotlinClassesApp = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/dhisDebug")){
7183
exclude(excludes)
7284
}
73-
val javaClasses = fileTree("${buildDir}/intermediates/javac/debug"){
85+
val javaClasses = fileTree(layout.buildDirectory.dir("intermediates/javac/debug")){
7486
exclude(excludes)
7587
}
76-
val kotlinClasses = fileTree("${buildDir}/tmp/kotlin-classes/debug"){
88+
val kotlinClasses = fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/debug")){
7789
exclude(excludes)
7890
}
7991

@@ -88,10 +100,10 @@ tasks.register("jacocoReport", JacocoReport::class) {
88100
)
89101
)
90102

91-
val unitTestsData = fileTree("${buildDir}/jacoco") {
103+
val unitTestsData = fileTree(layout.buildDirectory.dir("jacoco")) {
92104
include("*.exec")
93105
}
94-
val androidTestsData = fileTree("${buildDir}/outputs/code_coverage") {
106+
val androidTestsData = fileTree(layout.buildDirectory.dir("outputs/code_coverage")) {
95107
include(listOf("**/*.ec"))
96108
}
97109

@@ -106,23 +118,15 @@ tasks.register("jacocoReport", JacocoReport::class) {
106118

107119
fun JacocoReportsContainer.reports() {
108120
xml.required.set(true)
109-
xml.outputLocation.set(file("${buildDir}/coverage-report/jacocoTestReport.xml"))
121+
xml.outputLocation.set(layout.buildDirectory.file("coverage-report/jacocoTestReport.xml"))
110122

111123
html.required.set(true)
112-
html.outputLocation.set(file("${buildDir}/coverage-report"))
124+
html.outputLocation.set(layout.buildDirectory.dir("coverage-report"))
113125
}
114126

115127
reports {
116128
reports()
117129
}
118130
}
119131

120-
/*android {
121-
buildTypes {
122-
getByName("debug") {
123-
// jacoco test coverage reports both for
124-
// androidTest and test source sets
125-
testCoverageEnabled = false
126-
}
127-
}
128-
}*/
132+

login/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ plugins {
99
alias(libs.plugins.kotlin.serialization)
1010
}
1111

12+
apply(from = "${project.rootDir}/jacoco/jacoco-kmp.gradle.kts")
13+
1214
kotlin {
1315

1416
compilerOptions {

sync/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ plugins {
99
alias(libs.plugins.kotlin.serialization)
1010
}
1111

12+
apply(from = "${project.rootDir}/jacoco/jacoco-kmp.gradle.kts")
13+
1214
kotlin {
1315

1416
compilerOptions {

tracker/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ plugins {
55
alias(libs.plugins.kotlin.compose.compiler)
66
}
77

8+
apply(from = "${project.rootDir}/jacoco/jacoco-kmp.gradle.kts")
9+
810
kotlin {
911
androidTarget {
1012
compilerOptions {

0 commit comments

Comments
 (0)