@@ -3,6 +3,7 @@ package conventions
33import org.gradle.api.Plugin
44import org.gradle.api.Project
55import org.gradle.api.artifacts.VersionCatalogsExtension
6+ import org.gradle.api.file.FileTree
67import org.gradle.configurationcache.extensions.capitalized
78import org.gradle.kotlin.dsl.extra
89import org.gradle.kotlin.dsl.getByType
@@ -18,47 +19,47 @@ import ytemplate.android.jacoco.jacoco
1819 *
1920 * @constructor Create empty Library jacoco convention plugin
2021 */
22+ @Suppress(" UNCHECKED_CAST" )
2123class ProjectJacocoConventionPlugin : Plugin <Project > {
22- private val project_level_limits = mutableMapOf (
23- " instruction" to 0.0 ,
24- " branch" to 0.0 ,
25- " line" to 0.0 ,
26- " complexity" to 0.0 ,
27- " method" to 0.0 ,
28- " class" to 0.0
29- )
30-
31-
32- fun Project.setProjectTestCoverageLimits (projectLimits : Map <String , Double >? = null) {
33- if (projectLimits != null ) {
34- extra.set(" limits" , projectLimits)
35- } else {
36- extra.set(" limits" , project_level_limits)
37- }
38- }
39-
4024 override fun apply (target : Project ) {
4125 with (target) {
42- val libs = extensions.getByType<VersionCatalogsExtension >().named(" versionCatalogLibs" )
4326 with (pluginManager) {
4427 apply (" jacoco" )
4528 }
46- tasks.register<JacocoReport >(" MergeHTMLJacocoReports" ) {
29+
30+ tasks.register<JacocoReport >(" createMergedJacocoReport" ) {
4731 val jacocoReport = this
4832 group = " Reporting"
49- description = " Merge all generated JacocoReport "
33+ description = " create Project Jacoco Report for debug builds for all submodules with jacoco plugin "
5034 logger.quiet(" ======Merging HTML Reports=========" )
51- val javaClasses: MutableCollection <String > = mutableListOf ()
52- val kotlinClasses: MutableCollection <String > = mutableListOf ()
35+ val javaClasses: MutableCollection <FileTree > = mutableListOf ()
36+ val kotlinClasses: MutableCollection <FileTree > = mutableListOf ()
5337 val sourceDir: MutableCollection <String > = mutableListOf ()
5438 val coverageFiles: MutableCollection <String > = mutableListOf ()
39+
5540 subprojects {
5641 val subProject = this
5742 subProject.plugins.withType<JacocoPlugin >().configureEach {
5843 val moduleTask = tasks.findByName(" createDemoDebugJacocoReport" )
5944 jacocoReport.dependsOn(moduleTask)
60- javaClasses.add(" ${subProject.buildDir} /intermediates/javac/demoDebug/classes" )
61- kotlinClasses.add(" ${subProject.buildDir} /tmp/kotlin-classes/demoDebug" )
45+ }
46+ if (subProject.plugins.findPlugin(JacocoPlugin ::class .java)!= null ) {
47+ val excludedFiles: MutableCollection <String > = mutableListOf ()
48+ if (subProject.extra.has(" excludes" )) {
49+ excludedFiles.addAll(subProject.extra.get(" excludes" ) as List <String >)
50+ }
51+ javaClasses.add(fileTree(" ${subProject.buildDir} /intermediates/javac/demoDebug/classes" ) {
52+ if (excludedFiles.isNotEmpty()) {
53+ exclude(excludedFiles)
54+ }
55+
56+ }.asFileTree)
57+ kotlinClasses.add(fileTree(" ${subProject.buildDir} /tmp/kotlin-classes/demoDebug" ) {
58+ if (excludedFiles.isNotEmpty()) {
59+ exclude(excludedFiles)
60+ }
61+ }.asFileTree)
62+
6263 sourceDir.add(" ${subProject.projectDir} /src/main/java" )
6364 sourceDir.add(" ${subProject.projectDir} /src/main/kotlin" )
6465 sourceDir.add(" ${subProject.projectDir} /src/demoDebug/java" )
0 commit comments