How to set up custom findbugs task in gradle with another pluginClasspath plugin

I tried setting up a custom findbugs task with gradle, which would have a different pluginClass path than the standard ones.

Thus, default tasks should use standard FindBugs rules, while custom tasks should use findbugs security rules. My configuration looks like this:

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

However, if I now run the findbugsMain task, it also includes checks from findbugs-security!

How can I configure it so that search-based checks are only used in a custom task?

+6
source share
1 answer

It seems that setting the findbugsSecurity task also changes the behavior of findbugsMain , as you probably guessed.

The trick is to use the new configuration, as Gradle will automatically look for dependencies for the findbugsPlugins configuration and will be applied to all findbugs calls (see the pluginClasspath part of the 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) } 
+3
source

All Articles