Created
March 22, 2024 10:19
-
-
Save JoseAlcerreca/3d33fac0dffa909b3c1c41cc5cdf46d1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
... | |
jacoco | |
} | |
android { | |
applicationVariants.all(closureOf<com.android.build.gradle.api.ApplicationVariant> { | |
val myObjFactory = project.objects | |
val buildDir = layout.buildDirectory.get().asFile | |
val allJars: ListProperty<RegularFile> = myObjFactory.listProperty(RegularFile::class.java) | |
val allDirectories: ListProperty<Directory> = myObjFactory.listProperty(Directory::class.java) | |
val reportTask = | |
tasks.register("create${variant.name.capitalize()}CombinedCoverageReport", JacocoReport::class) { | |
classDirectories.setFrom( | |
allJars, | |
allDirectories.map { dirs -> | |
dirs.map { dir -> | |
myObjFactory.fileTree().setDir(dir).exclude(coverageExclusions) | |
} | |
} | |
) | |
reports { | |
xml.required.set(true) | |
html.required.set(true) | |
} | |
// TODO: This is missing files in src/debug/, src/prod, src/demo, src/demoDebug... | |
sourceDirectories.setFrom(files("$projectDir/src/main/java", "$projectDir/src/main/kotlin")) | |
executionData.setFrom( | |
project.fileTree("$buildDir/outputs/unit_test_code_coverage/${variant.name}UnitTest") | |
.matching { include("**/*.exec") }, | |
project.fileTree("$buildDir/outputs/code_coverage/${variant.name}AndroidTest") | |
.matching { include("**/*.ec") } | |
) | |
} | |
variant.artifacts.forScope(ScopedArtifacts.Scope.PROJECT) | |
.use(reportTask) | |
.toGet( | |
ScopedArtifact.CLASSES, | |
{ _ -> allJars }, | |
{ _ -> allDirectories }, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment