【问题标题】:How to configure a custom findbugs task in gradle with a different pluginClasspath如何使用不同的 pluginClasspath 在 gradle 中配置自定义 findbugs 任务
【发布时间】:2015-12-02 09:50:50
【问题描述】:

我尝试使用 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 检查仅在自定义任务中使用?

【问题讨论】:

    标签: gradle findbugs


    【解决方案1】:

    听起来配置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)
    }
    

    【讨论】:

    • 太棒了!我没有在文档中看到 findbugs 插件默认使用“findbugsPlugins”依赖项
    猜你喜欢
    • 2013-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多