Skip to content

Instantly share code, notes, and snippets.

@sinergy
Created September 2, 2015 05:44
Show Gist options
  • Save sinergy/a5d98f1e6f297e40c149 to your computer and use it in GitHub Desktop.
Save sinergy/a5d98f1e6f297e40c149 to your computer and use it in GitHub Desktop.
add FindBugs Gradle task into Android project
apply plugin: 'findbugs'
afterEvaluate {
def variants = plugins.hasPlugin('com.android.application') ?
android.applicationVariants : android.libraryVariants
variants.each { variant ->
def task = tasks.create("findBugs${variant.name.capitalize()}", FindBugs)
task.group = 'verification'
task.description = "Run FindBugs for the ${variant.description}."
task.excludeFilter = rootProject.file('config/findbugs-filter.xml')
task.effort = 'max'
task.reportLevel = 'high'
task.reports {
xml.enabled = false
html.enabled = true
xml {
destination "$project.buildDir/reports/findbugs/findbugs.xml"
}
html {
destination "$project.buildDir/reports/findbugs/findbugs.html"
}
}
def variantCompile = variant.javaCompile
task.classes = fileTree(variantCompile.destinationDir)
task.source = variantCompile.source
task.classpath = variantCompile.classpath.plus(project.files(android.bootClasspath))
task.dependsOn(variantCompile)
tasks.getByName('check').dependsOn(task)
}
}
@sinergy
Copy link
Author

sinergy commented Sep 2, 2015

Usage:

  1. Put this android-findbugs.gradle into your project. gradle directory might be good place for it.
  2. Apply this gradle file in your module-level build.gradle file

    for example: apply from: rootProject.file('gradle/android-findbugs.gradle')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment