Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 51 additions & 2 deletions designcompose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ android {
initWith(buildTypes.getByName("release"))
matchingFallbacks.add("release")
}
debug { enableUnitTestCoverage = true }
}

packaging {
Expand All @@ -69,10 +70,58 @@ android {
add("META-INF/LGPL2.1")
}
}
testOptions { unitTests { isIncludeAndroidResources = true } }
testOptions {
unitTests {
isIncludeAndroidResources = true
all { test ->
test.extensions.configure<JacocoTaskExtension> {
// These classes are not supposed to be accessible
excludes = listOf("jdk.internal.*")
isIncludeNoLocationClasses =
true // Include classes without location information
}
}
}
}
}

tasks.withType<Test> { jacoco { isEnabled = true } }
tasks.register<JacocoReport>("jacocoUnitTestReport") {
group = "verification"
dependsOn(tasks.named("testDebugUnitTest"))

// Point Jacoco to the source code. This correctly finds both Java and Kotlin files.
val mainSourceSet = android.sourceSets.getByName("main").java.srcDirs
sourceDirectories.setFrom(files(mainSourceSet))

val jacocoExcludes =
listOf(
"**/R.class",
"**/R$*.class",
"**/BuildConfig.*",
"**/Manifest*.*",
"**/*Test*.*",
// Add other classes or packages to exclude from coverage as needed
)

// Point Jacoco to the classes that were generated by the compilation
classDirectories.setFrom(
files(
fileTree(layout.buildDirectory.dir("intermediates/javac/")) { exclude(jacocoExcludes) },
fileTree(layout.buildDirectory.dir("tmp/kotlin-classes/")) { exclude(jacocoExcludes) },
)
)
// Collect execution data from .exec and .ec files generated during test execution
executionData.setFrom(
files(fileTree(layout.buildDirectory) { include(listOf("**/*.exec", "**/*.ec")) })
)

reports {
html.required.set(true)
html.outputLocation.set(
project.layout.buildDirectory.dir("reports/jacoco/jacocoUnitTestReport")
)
}
}

// To simplify publishing of the entire SDK, make the DesignCompose publish tasks depend on the
// Gradle Plugin's publish tasks
Expand Down
Loading