gradle JaCoCo排除被Sonar忽略

ftf50wuq  于 2023-04-21  发布在  其他
关注(0)|答案(1)|浏览(218)

我使用Gradle JaCoCo插件,根据排除列表,一些文件夹必须从测试覆盖检查中排除。但是当我运行gradle sonar时,所有这些文件夹都由Sonarcloud处理。
如何强制SonarCloud忽略这些文件夹?

jacocoTestReport {
dependsOn test
reports {
    xml.required = true
    html.required = true
}
afterEvaluate {
    classDirectories.setFrom(files(classDirectories.files.collect {
        fileTree(dir: it, exclude: [
                'by/litvin/localsandbox/model/*',
                'by/litvin/localsandbox/mapper/*',
                'by/litvin/localsandbox/data/*',
                'by/litvin/localsandbox/data/*',
                'by/litvin/localsandbox/messaging/event/*',
                'by/litvin/localsandbox/messaging/serializer/*',
                'by/litvin/localsandbox/config/*',
                'by/litvin/localsandbox/LocalSandboxApplication.*'
        ])
    }))
}

}

new9mtju

new9mtju1#

我找到了一个解决方案,JaCoCo排除列表是不够的,你需要在sonar插件配置中排除这些包:

sonarqube {
    properties {
        def projectPath = "**/*by/litvin/localsandbox"
        def exclusionList = [
                "${projectPath}/model/*",
                "${projectPath}/config/*",
                "${projectPath}/data/*",
                "${projectPath}/messaging/serializer/*",
                "${projectPath}/messaging/event",
                "${projectPath}/LocalSandboxApplication.*"
        ].join(', ')
        property "sonar.coverage.exclusions", exclusionList
    }
}

相关问题