Findbugs android gradle plugin

I have an Android project. I want to introduce findbugs in my project as a gradle plugin. I tried to modify the build.gradle project as shown below.

 buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0+' classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: "java" apply plugin: "findbugs" findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = false reportsDir = file("$project.buildDir/findbugsReports") effort = "max" reportLevel = "high" includeFilter = file("$rootProject.projectDir/config/findbugs/includeFilter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml") } 

Is this plugin correct? Do I need to add or remove any files? Now, what should I do to get the results of this findbugs check? Which gradle command to use?

+8
android android-gradle build.gradle findbugs gradlew
Apr 30 '15 at 12:04
source share
4 answers

Just put this in your build.gradle modules.

 apply plugin: 'findbugs' task customFindbugs(type: FindBugs) { ignoreFailures = false effort = "max" reportLevel = "low" classes = files("$project.buildDir/intermediates/classes") // Use this only if you want exclude some errors excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml") source = fileTree('src/main/java/') classpath = files() reports { xml.enabled = false xml.withMessages = true html.enabled = !xml.isEnabled() xml.destination "$project.buildDir/outputs/findbugs/findbugs-output.xml" html.destination "$project.buildDir/outputs/findbugs/findbugs-output.html" } } build.dependsOn customFindbugs 

Then, after changing the directory to your project path from the command line, use

 ./gradlew build 

The error report will be in $project.buildDir/outputs/findbugs/findbugs-output.html

+16
May 6 '15 at 6:08
source share
— -

I slightly changed the answer Nevin Raj Victor.

This version generates a findbug task for each build option, and (more importantly) it correctly creates dependencies on its respective compilation tasks. Indeed, findbugs requires the code to be compiled before it is parsed.

 // findbug tasks for each variant apply plugin: 'findbugs' android.applicationVariants.all { variant -> task("findbugs${variant.name.capitalize()}", type: FindBugs) { description "Analyze ${variant.name} code with the findbugs tool" group "Verification" ignoreFailures = true effort = "default" reportLevel = "medium" classes = files("$project.buildDir/intermediates/classes/${variant.dirName}") excludeFilter = file("$rootProject.rootDir/findbugs/findbugs-filter.xml") source = variant.javaCompile.source classpath = variant.javaCompile.classpath reports { // Only one of HTML or XML can be turned on at the same time html.enabled = true xml.enabled = !html.enabled xml.withMessages = true html.destination = "$project.buildDir/outputs/findbugs/findbugs-${variant.name}-output.html" xml.destination = "$project.buildDir/outputs/findbugs/findbugs-${variant.name}-output.xml" } dependsOn "compile${variant.name.capitalize()}JavaWithJavac" } } 

After that you can run

 ./gradlew findbugsDebug ./gradlew findbugsRelease 

Or other search tasks in different ways, depending on your configuration.

+9
May 13 '16 at 9:47
source share

I see some problems with your configuration:

  • instead of 2.0.1 use version 3.0.1
  • set reportLevel to low instead of high to report all violations
  • for the first analysis you do not need to configure any includeFilter or excludeFilter - these are just whitelists and checklist blacklists, if you need some kind of customization

To start the analysis, simply call gradle findbugsMain . Results should be visible at the exit.

0
Apr 30 '15 at 20:40
source share

Please take a look at this project https://github.com/Piasy/AndroidCodeQualityConfig .

This project includes lint, pmd, findbugs, checkstyle, jacoco code coverage. And a support project with submodules.

0
Mar 29 '17 at 5:46 on
source share



All Articles