WIP: Fixes code coverage

Change-Id: I04b4fcdd11824a72124da7122c799732a039ded9
ja/coverage
Jose Alcérreca 10 months ago
parent 3e4aad3210
commit 8bf51cfae3

@ -43,6 +43,7 @@ android {
buildTypes {
debug {
enableAndroidTestCoverage = true
applicationIdSuffix = NiaBuildType.DEBUG.applicationIdSuffix
}
release {

@ -27,9 +27,10 @@ class AndroidLibraryJacocoConventionPlugin : Plugin<Project> {
apply("org.gradle.jacoco")
apply("com.android.library")
}
val extension = extensions.getByType<LibraryAndroidComponentsExtension>()
val extension: LibraryAndroidComponentsExtension = extensions.getByType<LibraryAndroidComponentsExtension>()
configureJacoco(extension)
}
}
}
}

@ -19,6 +19,7 @@ package com.google.samples.apps.nowinandroid
import com.android.build.api.variant.AndroidComponentsExtension
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.withType
@ -46,30 +47,52 @@ internal fun Project.configureJacoco(
toolVersion = libs.findVersion("jacoco").get().toString()
}
val jacocoTestReport = tasks.create("jacocoTestReport")
androidComponentsExtension.onVariants { variant ->
val testTaskName = "test${variant.name.capitalize()}UnitTest"
val jvmTestTaskName = "test${variant.name.capitalize()}UnitTest"
val androidTestTaskName = "connected${variant.name.capitalize()}AndroidTest"
val buildDir = layout.buildDirectory.get().asFile
val reportTask = tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport::class) {
dependsOn(testTaskName)
listOf(jvmTestTaskName, androidTestTaskName).forEach { testTaskName ->
val reportTask =
tasks.register("jacoco${testTaskName.capitalize()}Report", JacocoReport::class) {
dependsOn(testTaskName)
reports {
xml.required.set(true)
html.required.set(true)
}
classDirectories.setFrom(
// TODO: Hack suggested in https://issuetracker.google.com/161300933
// fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
// exclude(coverageExclusions)
// }
reports {
xml.required.set(true)
html.required.set(true)
}
fileTree("$buildDir/intermediates/classes/${variant.name}/transform${variant.name.capitalize()}ClassesWithAsm/dirs") {
exclude(coverageExclusions)
}
)
classDirectories.setFrom(
fileTree("$buildDir/tmp/kotlin-classes/${variant.name}") {
exclude(coverageExclusions)
sourceDirectories.setFrom(
files(
"$projectDir/src/main/java",
"$projectDir/src/main/kotlin"
)
)
executionData.setFrom(
file("$buildDir/jacoco/$testTaskName.exec"),
file("$buildDir/**/coverage.ec"),
// Beware of using '**' with directories that contain spaces!
project.fileTree("$buildDir/outputs/code_coverage")
.matching { include("**/*.ec") }
)
}
)
sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin"))
executionData.setFrom(file("$buildDir/jacoco/$testTaskName.exec"))
jacocoTestReport.dependsOn(reportTask)
}
jacocoTestReport.dependsOn(reportTask)
}
tasks.withType<Test>().configureEach {

@ -2,7 +2,7 @@
accompanist = "0.32.0"
androidDesugarJdkLibs = "2.0.4"
# AGP and tools should be updated together
androidGradlePlugin = "8.3.0"
androidGradlePlugin = "8.4.0-alpha13"
androidTools = "31.3.0"
androidxActivity = "1.8.0"
androidxAppCompat = "1.6.1"
@ -17,7 +17,7 @@ androidxDataStore = "1.0.0"
androidxEspresso = "3.5.1"
androidxHiltNavigationCompose = "1.2.0"
androidxLifecycle = "2.7.0"
androidxMacroBenchmark = "1.2.2"
androidxMacroBenchmark = "1.2.3"
androidxMetrics = "1.0.0-alpha04"
androidxNavigation = "2.7.4"
androidxProfileinstaller = "1.3.1"

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

Loading…
Cancel
Save