【问题标题】:Jacoco Kotlin Dsl Multimodule excludeJacoco Kotlin Dsl 多模块排除
【发布时间】:2020-09-03 02:33:58
【问题描述】:

我正在尝试从合并的 jacoco 报告中排除一些文件。我正在使用:

(根等级)

    tasks.register<JacocoReport>("codeCoverageReport") {
    subprojects {
        val subProject = this
        subProject.plugins.withType<JacocoPlugin>().configureEach {
            subProject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.configureEach {
                val testTask = this
                sourceSets(subProject.sourceSets.main.get())
                executionData(testTask)
            }

            subProject.tasks.matching { it.extensions.findByType<JacocoTaskExtension>() != null }.forEach {
                rootProject.tasks["codeCoverageReport"].dependsOn(it)
            }
        }
    }

    reports {
        xml.isEnabled = false
        html.isEnabled = true
        csv.isEnabled = false
    }
}

对于每个模块排除 jacoco 报告(例如,对于公共模块):

tasks.withType<JacocoReport> {
    classDirectories.setFrom(
        sourceSets.main.get().output.asFileTree.matching {
            exclude(JacocoExcludes.commonModule)
        }
    )
}

对于每个模块,这是有效的,但是当尝试与根 gradle 任务交互时,gradle 同步失败或者它只添加最后一个模块的文件。有什么帮助吗?

谢谢

【问题讨论】:

    标签: gradle jacoco gradle-kotlin-dsl


    【解决方案1】:

    我遇到了同样的问题并使用了以下代码:

    tasks.jacocoTestReport {
        // tests are required to run before generating the report
        dependsOn(tasks.test) 
        // print the report url for easier access
        doLast {
            println("file://${project.rootDir}/build/reports/jacoco/test/html/index.html")
        }
        classDirectories.setFrom(
            files(classDirectories.files.map {
                fileTree(it) {
                    exclude("**/generated/**", "**/other-excluded/**")
                }
            })
        )
    }
    

    这里建议:https://github.com/gradle/kotlin-dsl-samples/issues/1176#issuecomment-610643709

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-10
      • 1970-01-01
      • 2020-05-18
      • 2022-09-25
      • 1970-01-01
      相关资源
      最近更新 更多