From a75a0c4d4691ce3ad19fd19d1c8e9066c52da093 Mon Sep 17 00:00:00 2001 From: Kenneth Soh Date: Thu, 23 Apr 2026 17:35:57 +0800 Subject: [PATCH] build: Switch to use Android's Native coverage check --- .github/workflows/sonarcloud.yml | 2 +- build.gradle.kts | 3 ++- gradle/libs.versions.toml | 1 - helperlib/build.gradle.kts | 42 -------------------------------- 4 files changed, 3 insertions(+), 45 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 7bebc61..1bc2fb0 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -31,7 +31,7 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} restore-keys: ${{ runner.os }}-gradle - name: Run tests, linting and coverage generation first - run: ./gradlew lint jacocoTestReport + run: ./gradlew lint createDebugUnitTestCoverageReport - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any diff --git a/build.gradle.kts b/build.gradle.kts index ebe68f1..ce96aca 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,6 +14,7 @@ sonarqube { property("sonar.androidLint.reportPaths", "helperlib/build/reports/lint-results-debug.xml") property("sonar.projectVersion", project(":helperlib").ext.get("version") ?: "1.0") property("sonar.tests", "src/test/java,src/test/kotlin") - property("sonar.coverage.jacoco.xmlReportPaths", "build/reports/jacoco/jacocoTestReport/jacocoTestReport.xml") + property("sonar.coverage.jacoco.xmlReportPaths", "**/build/reports/coverage/test/debug/report.xml") + property("sonar.java.binaries", "**/build/intermediates/javac/*/classes") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3ad0b5c..f0261f5 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -33,7 +33,6 @@ volley = { module = "com.android.volley:volley", version.ref = "volley" } [plugins] android-library = { id = "com.android.library", version.ref = "androidLibrary" } -jacoco = { id = "jacoco" } kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlinAndroid" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlinSerialization" } sonarqube = { id = "org.sonarqube", version.ref = "sonarqube" } diff --git a/helperlib/build.gradle.kts b/helperlib/build.gradle.kts index 16d46c2..5891b39 100644 --- a/helperlib/build.gradle.kts +++ b/helperlib/build.gradle.kts @@ -4,7 +4,6 @@ plugins { alias(libs.plugins.android.library) alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.serialization) - alias(libs.plugins.jacoco) } ext.set("version", "2.3.2") @@ -78,46 +77,5 @@ dependencies { implementation(libs.volley) } -tasks.register("jacocoTestReport") { - dependsOn("testDebugUnitTest") - group = "verification" - description = "Generate Jacoco coverage reports for the debug build." - - reports { - xml.required.set(true) - html.required.set(true) - } - - val fileFilter = listOf( - "**/R.class", "**/R$*.class", "**/BuildConfig.*", "**/Manifest*.*", - "**/*Test*.*", "android/**/*.*" - ) - - val buildDir = layout.buildDirectory.get().asFile.path - - val debugTree = fileTree("$buildDir/intermediates/javac/debug/classes") { - exclude(fileFilter) - } - val kotlinDebugTree = fileTree("$buildDir/tmp/kotlin-classes/debug") { - exclude(fileFilter) - } - - val mainSrc = "$projectDir/src/main/java" - val kotlinSrc = "$projectDir/src/main/kotlin" - - sourceDirectories.setFrom(files(mainSrc, kotlinSrc)) - classDirectories.setFrom(files(debugTree, kotlinDebugTree)) - - executionData.setFrom( - fileTree(buildDir) { - include( - "jacoco/testDebugUnitTest.exec", - "outputs/unit_test_code_coverage/debugUnitTest/testDebugUnitTest.exec" - ) - } - ) - -} - // Apply the publish.gradle file apply(from = "./publish.gradle") \ No newline at end of file