我正在使用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' }
}
由于
答案 0 :(得分:1)
试试这个:
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应该与您的WORKSPACE相关,即src / java / com /.../...)
答案 1 :(得分:0)
sonarRunner插件已弃用。请切换到官方SonarQube插件:https://plugins.gradle.org/plugin/org.sonarqube