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

如何使用不同的pluginClasspath在gradle中配置自定义findbugs任务,gradle,findbugs,Gradle,Findbugs,我试着用gradle设置一个定制的findbugs任务,它将有一个不同于默认路径的pluginClasspath 因此,默认任务应该使用默认的FindBugs规则,而自定义任务应该使用FindBugs安全规则。我的配置如下所示: dependencies { findbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.4.4' } findbugs { // general config } task findbug

我试着用gradle设置一个定制的findbugs任务,它将有一个不同于默认路径的pluginClasspath

因此,默认任务应该使用默认的FindBugs规则,而自定义任务应该使用FindBugs安全规则。我的配置如下所示:

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安全性的检查


我如何配置它,使findbugs安全检查只在自定义任务中使用?

这听起来像是配置
findbugsSecurity
任务也在改变
findbugsMain
的行为,正如您可能猜到的那样

诀窍是使用新配置,因为Gradle将自动查找FindBugsLugins配置的依赖项,该依赖项将应用于findbugs的所有调用(请参阅):


伟大的我在文档中没有看到findbugs插件默认使用“findbugsPlugins”依赖项
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)
}