在Gradle中的Findbugs和Checkstyle插件中使用"排除"配置

Mar*_*erg 13 findbugs checkstyle gradle

我有以下Gradle构建文件:https://github.com/markuswustenberg/jsense/blob/a796055f984ec309db3cc0f3e8340cbccac36e4e/jsense-protobuf/build.gradle其中包括:

checkstyle {
  // TODO The excludes are not working, ignore failures for now
  //excludes '**/org/jsense/serialize/protobuf/gen/**'
  ignoreFailures = true
  showViolations = false
}

findbugs {
  // TODO The excludes are not working, ignore failures for now
  //excludes '**/org/jsense/serialize/protobuf/gen/**'
  ignoreFailures = true
}
Run Code Online (Sandbox Code Playgroud)

如您所见,我正在尝试在org.jsense.serialize.protobuf.gen包中排除自动生成的代码.我无法弄清楚为excludes参数提供的字符串的格式,并且文档没有多大帮助:http://www.gradle.org/docs/1.10/dsl/org.gradle.api.plugins.quality .FindBugs.html#org.gradle.api.plugins.quality.FindBugs:排除(它只是说"排除模式集".).

所以我的问题是:如何为Findbugs和Checkstyle插件格式化排除模式字符串?

我正在运行Gradle 1.10.

谢谢!

编辑1:我得到Checkstyle排除使用以下内容:

tasks.withType(Checkstyle) {
  exclude '**/org/jsense/serialize/protobuf/gen/**'
}
Run Code Online (Sandbox Code Playgroud)

但是,在Findbugs插件上使用完全相同的排除不起作用:

tasks.withType(FindBugs) {
  exclude '**/org/jsense/serialize/protobuf/gen/*'
}
Run Code Online (Sandbox Code Playgroud)

编辑2:接受的答案是有效的,使用XML文件并对其进行过滤也是如此,如下所示:

findbugs {
  excludeFilter = file("$projectDir/config/findbugs/excludeFilter.xml")
}
Run Code Online (Sandbox Code Playgroud)

<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
  <Match>
    <Package name="org.jsense.serialize.protobuf.gen"/>
  </Match>
</FindBugsFilter>
Run Code Online (Sandbox Code Playgroud)

编辑3:这很好用,不需要XML文件:

def excludePattern = 'org/jsense/serialize/protobuf/gen/'
def excludePatternAntStyle = '**/' + excludePattern + '*'
tasks.withType(FindBugs) {
    classes = classes.filter {
        !it.path.contains(excludePattern)
    }
}
tasks.withType(Checkstyle) {
    exclude excludePatternAntStyle
}
tasks.withType(Pmd) {
    exclude excludePatternAntStyle
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*ser 13

SourceTask#exclude过滤源文件.但是,FindBugs主要对类文件进行操作,您也必须对其进行过滤.尝试类似的东西:

tasks.withType(FindBugs) {
    exclude '**/org/jsense/serialize/protobuf/gen/*'
    classes = classes.filter { 
        !it.path.contains(new File("org/jsense/serialize/protobuf/gen/").path) 
    }
}
Run Code Online (Sandbox Code Playgroud)

PS:在FindBugs的情况下,过滤源文件可能没有区别(因此也没有必要).(我没试过.)