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.
Martin Devillers May 13 '16 at 9:47 p.m. 2016-05-13 21:47
source share