我尝试使用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)
}

10-08 04:49