当前位置: 首页 > 知识库问答 >
问题:

在Findbugs中使用“excluses”配置,在Gradle中使用Checkstyle插件

郭志泽
2023-03-14

我有以下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
}
tasks.withType(Checkstyle) {
  exclude '**/org/jsense/serialize/protobuf/gen/**'
}
tasks.withType(FindBugs) {
  exclude '**/org/jsense/serialize/protobuf/gen/*'
}
findbugs {
  excludeFilter = file("$projectDir/config/findbugs/excludeFilter.xml")
}
<?xml version="1.0" encoding="UTF-8"?>
<FindBugsFilter>
  <Match>
    <Package name="org.jsense.serialize.protobuf.gen"/>
  </Match>
</FindBugsFilter>
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
}

共有1个答案

韦睿
2023-03-14

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) 
    }
}

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

 类似资料:
  • 我们在Java中有一个多项目构建,其中8个项目中有两个是系统测试,我们不想针对系统测试代码(位于'src/main/Java'中)运行FindBugs或Checkstyle。 我在顶级build.gradle文件中启用了findbugs/checkstyle,但想要“禁用”插件在这两个项目中运行?

  • E:/home/example/documents/gradle-com.example.hello-plugin/src/main/kotlin/com/example/helloplugin.kt:(11,27):以下任何函数都不能用提供的参数调用: public抽象fun register(P0:String,p1:Class,vararg p2:any!):在org.gradle.api.

  • Mark问这是什么样子的,下面是这段代码。 pom和Checkstyle配置文件都正常工作,但 如果它是Treewalker的子文件,我会从Maven插件得到错误,但不能从Eclipse插件得到错误,不过,我只能让它与Eclipse插件一起工作。

  • 我有一个多项目的gradle构建,其中一个子项目是应用Artifactory插件(版本4.2.0),并配置contextUrl和resolve repoKey。 它设置一个简单的配置和依赖项,然后有一个复制任务来检索依赖项作为zip文件并将其解压缩到目录中。 然而,当复制任务运行时,我得到下面的错误。我做错了什么?这是Artifactory插件或gradle的问题,还是。。。? 问题似乎与该项目是

  • 多项目Gradle构建中的子项目如何使用根项目的buildSrc文件夹中定义的Gradle插件? 我基本上有: 设置。格拉德尔 buildSrc/src/main/groovy/com/example/conventions/JavaConventionsPlugin。groovy buildSrc/build。格拉德尔 通用/构建。格拉德尔 我正在尝试在项目中应用插件: 但是上面说 id为“co

  • 我有一个使用gradle kotlin dsl构建的java项目。 现在我想像这样使用gradle-avro-plugin https://github . com/davidmc 24/gradle-avro-plugin # alternate-usage 在 kotlin dsl 中,我编写了与下面相同的逻辑 - 当我运行< code>grade compileJava时,上面的代码返回以下