gpt4 book ai didi

gradle - 从gradle中排除所有分析的测试类

转载 作者:行者123 更新时间:2023-12-03 05:01:33 26 4
gpt4 key购买 nike

我正在使用gradle的sonar-runner插件调用声纳。我也在使用重用报告标志。
如何从所有分析(Checkstyle,Findbugs,Coverage)中排除所有测试类?

我目前正在使用以下插件配置:

sonarRunner {
sonarProperties {
property "sonar.host.url", "<HOST>"

property "sonar.scm.disabled", "true"
property "sonar.login", "<USER>"
property "sonar.password", "<password>"

property "sonar.sources", "src"
property "sonar.exclusions", "**/test/**/*.java"
property "sonar.projectVersion", project.releaseDisplayName
// these should not change anything as sonar uses the defaults set for gradle
//property "sonar.tests", "test"
}

我的源集如下:
sourceSets {
main {
java {
srcDir 'src'
srcDir 'src-gen'
}
}
test {
java { srcDir 'test' }
}

谢谢

最佳答案

试试这个:

jacocoTestReport {
afterEvaluate {
sourceDirectories = files(sourceDirectories.files.collect {
fileTree(dir: it, exclude: [ 'com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**' ])
})
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: [ 'com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**' ])
})
}
}

sonarRunner {
sonarProperties {
property "sonar.exclusions", "com/path/to/package/that/I/want/to/exclude/are/inside/thisfolder_or_dto/**"
}
}

//Required with Gradle 2.0+ -- 2.0+ -- 2.3
pmd {
ruleSets = ["java-basic", "java-braces", "java-design" ]
ignoreFailures = true
}

codenarc {
ignoreFailures = true
//The following file should exist or build will fail, you can find one online a sample version
configFile = file("config/codenarc/codenarc.xml")
}


checkstyle {
configFile = new File(rootDir, "config/checkstyle.xml")
ignoreFailures = true
//sourceSets = [sourceSets.main, sourceSets.test, sourceSets.integrationTest]

//Just run checkstyle only on main source code
sourceSets = [sourceSets.main]
}


findbugs {
ignoreFailures = true
//Just run findbugs only on main source code
sourceSets = [sourceSets.main]

//You can use if statement in groovy to set which toolVersion 2.0.3 or 3.0.1 depending upon JAVA version used in the project
toolVersion = "3.0.1"
}

同样,您可以在测试或测试任务的jacoco部分中直接使用excludes属性。
    def generatedSources = ['com/yahoo/**', 'com/amazon/**']

test {
jacoco {
excludes = generatedSources
}
}

jacocoTestReport {
doFirst {
classDirectories = fileTree(dir: "${buildDir}/classes/main/").exclude(generatedSources)
}
reports {
xml.enabled true
}
}

在发布到SonarQube时(sonar.exclusions = value应该相对于您的工作空间相对,即src / java / com / ... / ...)

关于gradle - 从gradle中排除所有分析的测试类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33633355/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com