gradle - 如何使用不同的 pluginClasspath 在 gradle 中配置自定义 findbugs 任务

标签 gradle findbugs

我试图用 gradle 设置一个自定义的 findbugs 任务,它的 pluginClasspath 与默认的不同。

因此,默认任务应使用默认 FindBugs 规则,而自定义任务应使用 findbugs-security 规则。我的配置是这样的:

dependencies {
  findbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.4.4'
}

findbugs {
  // general config
}

task findbugsSecurity(type: FindBugs, dependsOn: classes) {
  classes = fileTree(project.sourceSets.main.output.classesDir)
  source = project.sourceSets.main.java.srcDirs
  classpath = files()

  pluginClasspath = files(configurations.findbugsPlugins.asPath)
}

但是,如果我现在运行 findbugsMain 任务,它还包括来自 findbugs-security 的检查!

如何配置它以便 findbugs-security 检查仅用于自定义任务?

最佳答案

听起来像配置 findbugsSecurity任务也改变了 findbugsMain 的行为你可能已经猜到了。

诀窍是使用新配置,因为 Gradle 会自动查找 findbugsPlugins 配置的依赖项,这将适用于所有 findbugs 调用(参见 pluginClasspath part of FindBugs DSL):

configurations {
   foo
}

dependencies {
  // Important that we use a new configuration here because Gradle will use the findbugsPlugins configurations by default
  foo 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.4.4'
}

findbugs { /* whatever */ }

task findbugsSecurity(type: FindBugs, dependsOn: classes) {
  classes = fileTree(project.sourceSets.main.output.classesDir)
  source = project.sourceSets.main.java.srcDirs
  classpath = files()
  pluginClasspath = files(configurations.foo.asPath)
}

关于gradle - 如何使用不同的 pluginClasspath 在 gradle 中配置自定义 findbugs 任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34039579/

相关文章:

java - 如何从具有 gradle 依赖性的代码创建 Android 库?

java - 避免警告 "boxing immediately unboxed to perform coercion"

java - 非空注释和标准 java 包

java - FindBug 未从 javax.annotation.Nullable 方法中检测到 null

android - Gradle构建成功,但不会同步

gradle - Gradle:从任务中调用Groovy静态方法

java - 运行 Gradle 导致 - 错误 : Could not find or load main class security. provider.1=org.bouncycaSTLe.jce.provider.BouncyCaSTLeProvider

android - 无法使用react-native-navigation构建react-native

java - 为什么 FindBugs 会忽略我的 null 检查?

maven - 在使用 sonar 和 Maven 时如何配置 findbugs