FindBugs Android Gradle No classes configured error

Viewed 6448

I am trying to use the FindBugs plugin for Gradle with an Android build.

The build.gradle file

buildscript {
  repositories {
    mavenCentral()        
  }
  dependencies {
    classpath 'com.android.tools.build:gradle:0.6.+'
  }
}
apply plugin: 'android'
apply plugin: 'findbugs'

android {
  compileSdkVersion 19
  buildToolsVersion "19.0.0"
  defaultConfig {
    minSdkVersion 8
    targetSdkVersion 19        
  }
}

dependencies {
  compile 'com.android.support:appcompat-v7:+'
}

But when I execute the check task it says

No classes configured for FindBugs analysis.

How do I configure classes for FindBugs analysis?

6 Answers

As other people wrote, you have to set sourceSets, i.e.:

task findbugs(type: FindBugs) {
    // ignoreFailures = false
    ignoreFailures = true
    effort = 'max'
    reportLevel = 'low'
    excludeFilter = file("quality/findbugs/findbugs-filter.xml")
    classes = files("${project.buildDir}/intermediates/javac/debug/classes",

    source "${file(getProjectDir().getPath()).getAbsolutePath()}/src"
    include '**/*.java'
    exclude "${project.buildDir}/generated/**/*.java"

    reports {
        xml.enabled = true
        xml {
            destination file("findbugs/report.xml")
        }
        /*
        html.enabled = true
        html {
            destination file("findbugs/report.html")
        }
        */
        /*
        text.enabled = true
        text {
            destination file("findbugs/report.txt")
        }
        */
    }

    classpath = files()
}

The problem is that when you upgrade version of Android Gradle Plugin, this path changes now and then.

In our project in different times it was of following values:

"${project.buildDir}/intermediates/classes/debug"
"${project.buildDir}/intermediates/javac/debug/compileDebugJavaWithJavac/classes"
"${project.buildDir}/intermediates/javac/debug/classes"

So if none of mentioned above values worked out, try to find actual classes in your build tree, maybe they just changed it again.

Related