caipivara
11/6/2015 - 8:20 PM

Gradle / Android tasks to run findbugs and pmd static code checkers after assembleDebug. thanks to https://gist.github.com/rciovati/8461832

Gradle / Android tasks to run findbugs and pmd static code checkers after assembleDebug. thanks to https://gist.github.com/rciovati/8461832

apply plugin: 'findbugs'
apply plugin: 'pmd'

findbugs {
  ignoreFailures = true
  reportsDir = file("$project.buildDir/outputs/")
  reportLevel = "medium"
  effort = "max"
}

pmd {
  ignoreFailures = true
  reportsDir = file("$project.buildDir/outputs/")
}

task findbugs(type: FindBugs, dependsOn: assembleDebug) {
  description 'Run findbugs'
  group 'verification'

  classes = fileTree("build/intermediates/classes/debug/")
  source = fileTree('src/main/java')
  classpath = files()

  effort = 'max'

  excludeFilter = file("../setup/findbugs_exclude.xml")

  reports {
    xml.enabled = false
    html.enabled = true
  }
}

task pmd(type: Pmd, dependsOn: assembleDebug) {
  description 'Run pmd'
  group 'verification'

  ruleSets = ["java-basic", "java-braces", "java-strings", "java-design", "java-unusedcode"]
  source = fileTree('src/main/java')

  reports {
    xml.enabled = false
    html.enabled = true
  }
}

check.doLast {
  project.tasks.getByName("findbugs").execute()
  project.tasks.getByName("pmd").execute()
}
<FindBugsFilter>

  <Match>
    <Class name="~.*R\$.*" />
  </Match>
  <Match>
    <Class name="~.*Manifest\$.*" />
  </Match>

</FindBugsFilter>*R
// How to use it inside any gradle build
apply from: "quality.gradle"