From 76125354cd1f5dc4f42718c5ea2bc1b445bcdf3e Mon Sep 17 00:00:00 2001 From: andreia Date: Wed, 11 Mar 2026 15:48:08 +0100 Subject: [PATCH 1/3] add jacoco support for kmp modules --- config/jacoco/jacoco.gradle | 63 +++++++++++++++++++++++------------- core/domain/build.gradle.kts | 2 ++ 2 files changed, 42 insertions(+), 23 deletions(-) diff --git a/config/jacoco/jacoco.gradle b/config/jacoco/jacoco.gradle index d215c5f274..5cadf3fcd5 100644 --- a/config/jacoco/jacoco.gradle +++ b/config/jacoco/jacoco.gradle @@ -25,8 +25,44 @@ tasks.withType(Test).configureEach { jacoco.excludes = ['jdk.internal.*'] } +def isAndroidModule = plugins.hasPlugin('com.android.application') || plugins.hasPlugin('com.android.library') +def isKmpModule = plugins.hasPlugin('org.jetbrains.kotlin.multiplatform') +def excludesList = [ + '**/databinding/*', + '**/proto/*', + '**/migration/*', + '**/local/room/dao/*', + '**/*_Factory*', + '**/*Hilt*', + '**/*Args*', + '**/*Directions*', + '**/LocalDatabase_Impl*', + '**/*Module*', + '**/data/remote/firebase/base/*', + '**/data/remote/firebase/schema/*Reference*', + '**/data/remote/firebase/FirebaseStorageManager*', + '**/data/remote/firebase/FirestoreDataStore*', + '**/system/channel/LocationSharedFlowCallback*', +] +def testTaskName +def classDirs +def sourceDirs +def execData + +if (isAndroidModule) { + testTaskName = 'testLocalDebugUnitTest' + classDirs = 'build/intermediates/classes/localDebug/transformLocalDebugClassesWithAsm/dirs/org/groundplatform/android' + sourceDirs = ['src/main/java/org/groundplatform/android'] + execData = 'build/jacoco/testLocalDebugUnitTest.exec' +} else if (isKmpModule) { + testTaskName = 'jvmTest' + classDirs = 'build/classes/kotlin/jvm/main' + sourceDirs = ['src/commonMain/kotlin'] + execData = 'build/jacoco/jvmTest.exec' +} + tasks.register('jacocoLocalDebugUnitTestReport', JacocoReport) { - dependsOn 'testLocalDebugUnitTest' + dependsOn tasks.named(testTaskName) group = "Reporting" description = "Run tests and generate coverage reports" reports { @@ -34,26 +70,7 @@ tasks.register('jacocoLocalDebugUnitTestReport', JacocoReport) { xml.required = true html.required = true } - classDirectories.from = fileTree( - dir: 'build/intermediates/classes/localDebug/transformLocalDebugClassesWithAsm/dirs/org/groundplatform/android', - excludes: [ - '**/databinding/*', - '**/proto/*', - '**/migration/*', - '**/local/room/dao/*', - '**/*_Factory*', - '**/*Hilt*', - '**/*Args*', - '**/*Directions*', - '**/LocalDatabase_Impl*', - '**/*Module*', - '**/data/remote/firebase/base/*', - '**/data/remote/firebase/schema/*Reference*', - '**/data/remote/firebase/FirebaseStorageManager*', - '**/data/remote/firebase/FirestoreDataStore*', - '**/system/channel/LocationSharedFlowCallback*', - ] - ) - sourceDirectories.from = files('src/main/java/org/groundplatform/android') - executionData.from = files('build/jacoco/testLocalDebugUnitTest.exec') + classDirectories.from = fileTree(dir: classDirs, excludes: excludesList) + sourceDirectories.from = files(sourceDirs) + executionData.from = files(execData) } diff --git a/core/domain/build.gradle.kts b/core/domain/build.gradle.kts index 96409a8d81..ce60f49bbf 100644 --- a/core/domain/build.gradle.kts +++ b/core/domain/build.gradle.kts @@ -19,6 +19,8 @@ plugins { alias(libs.plugins.kotlin.serialization) } +apply(from = "../../config/jacoco/jacoco.gradle") + kotlin { // We do not add an Android target here because this is a pure domain module. // Adding an Android target would require the Android Gradle Plugin (AGP) and SDK configuration, From f81c8742a332b6b47d2d106da079034e6173b69b Mon Sep 17 00:00:00 2001 From: andreia Date: Wed, 11 Mar 2026 18:53:37 +0100 Subject: [PATCH 2/3] update codecov ci step to dynamically find all jacoco reports --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e29a9c5825..d8fa5a7985 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -53,7 +53,7 @@ jobs: run: | curl -Os https://uploader.codecov.io/latest/linux/codecov chmod +x codecov - ./codecov --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f app/build/reports/jacoco/jacocoLocalDebugUnitTestReport/jacocoLocalDebugUnitTestReport.xml + ./codecov --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f "*/build/reports/jacoco/**/*.xml" instrumentation-tests: needs: build From a102b2604a99978ffdd0e7405c8410bfc487635d Mon Sep 17 00:00:00 2001 From: andreia Date: Wed, 11 Mar 2026 18:58:41 +0100 Subject: [PATCH 3/3] use github action for codecov step --- .github/workflows/ci.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8fa5a7985..26f30ddef7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,10 +50,12 @@ jobs: run: ./gradlew jacocoLocalDebugUnitTestReport - name: Upload coverage to Codecov - run: | - curl -Os https://uploader.codecov.io/latest/linux/codecov - chmod +x codecov - ./codecov --verbose upload-process --fail-on-error -t ${{ secrets.CODECOV_TOKEN }} -n 'service'-${{ github.run_id }} -F service -f "*/build/reports/jacoco/**/*.xml" + uses: codecov/codecov-action@v5 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: "**/build/reports/jacoco/**/*.xml" + flags: service + fail_ci_if_error: true instrumentation-tests: needs: build