使用;不包括「;Findbugs中的配置和Gradle中的Checkstyle插件

使用;不包括「;Findbugs中的配置和Gradle中的Checkstyle插件,gradle,checkstyle,findbugs,Gradle,Checkstyle,Findbugs,我有以下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 wor

我有以下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
}
如您所见,我试图在包org.jsense.serialize.protobuf.gen中排除自动生成的代码。我无法确定给定给excludes参数的字符串的格式,文档也没有太大帮助:(它只是说“排除模式集”)

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

我正在运行Gradle 1.10

谢谢

编辑1:我得到了Checkstyle exclude,用于处理以下内容:

tasks.withType(Checkstyle) {
  exclude '**/org/jsense/serialize/protobuf/gen/**'
}
但是,在Findbugs插件上使用完全相同的排除不起作用:

tasks.withType(FindBugs) {
  exclude '**/org/jsense/serialize/protobuf/gen/*'
}
编辑2:接受的答案有效,使用XML文件并对其进行过滤也有效,如下所示:

findbugs {
  excludeFilter = file("$projectDir/config/findbugs/excludeFilter.xml")
}

SourceTask#排除
筛选源文件。然而,FindBugs主要对类文件进行操作,您还必须对这些类文件进行过滤。尝试以下方法:

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

PS:对于FindBugs,过滤源文件可能没有什么区别(因此没有必要)。(我还没试过。)

如果有人在寻找现代解决方案:
对于checkstyle,您可以在build.gradle中使用如下内容:

checkstyleMain.exclude '**/org/jsense/serialize/protobuf/gen/**'
如果要排除多个路径
解决方案1:

checkstyleMain.exclude '**/org/jsense/serialize/protobuf/gen/**'
checkstyleMain.exclude '**/org/example/some/random/path/**'
解决方案2:

checkstyleMain {
    setExcludes(new HashSet(['**/org/jsense/serialize/protobuf/gen/**', '**/org/example/some/random/path/**']))
}

我感觉这是Findbugs插件中的一个bug。excludes对Checkstyle和PMD都很好,并且根据文档,它们应该具有相同的格式。我将其用于外部excludes文件(请参阅),因此我认为它确实是Findbugs gradle插件中的一个bug。当我找到方法后,我会提交一个bug。对,这里报道:酷,谢谢,这很有效。这意味着我可能还没有发现一个bug。然而,我认为“排除”只在源代码上起作用是相当违反直觉的。这不是我在阅读文档后使用插件时所期望的,尤其是当它与Checkstyle和PMD一起工作时。想法?Checkstyle和PMD主要操作源文件,因此
SourceTask#exclude
对它们来说已经足够了。如果有一种更简单的方法来过滤FindBugs类会很好,但目前还不清楚如何做到这一点,尤其是以向后兼容的方式。关于你的PS:过滤源代码绝对没有什么区别。我想那方法是很没用的,是吗?或者有没有一个用例,FindBugs实际上检查了源代码?它确实使用了源代码(至少在某些情况下),但我猜类文件决定了要分析的内容。
checkstyleMain.exclude '**/org/jsense/serialize/protobuf/gen/**'
checkstyleMain.exclude '**/org/example/some/random/path/**'
checkstyleMain {
    setExcludes(new HashSet(['**/org/jsense/serialize/protobuf/gen/**', '**/org/example/some/random/path/**']))
}