FindBugs Android Gradle No classes configured error
Asked Answered
Z

6

9

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?

Zacharia answered 11/12, 2013 at 8:58 Comment(0)
M
12

This is not possible at the moment as findbugs expect Gradle's normal Java SourceSets but the android plugin uses custom ones.

There's work planned in both Gradle and in the Android plugin to allow using the default SourceSets which will enable FindBugs.

You track this issue here: https://code.google.com/p/android/issues/detail?id=55839

Mahout answered 12/12, 2013 at 0:25 Comment(0)
S
4

In newer versions of Android Studio this problem could be attributed to the fact that the location of the classes directory has changed.

The new location (as of 0.8.2) is:

build/intermediates/classes/{build_variant_name}/

for example

build/intermediates/classes/debug/
task findbugs(type: FindBugs) {
    excludeFilter = file('config/findbugs/findbugs.xml')
    ignoreFailures = true
    classes = fileTree('build/intermediates/classes/preproduction/')
    source = fileTree('src/main/java/')
    classpath = files()
    effort = 'max'
    reports {
        xml {
            destination "reports/findbugs.xml"
        }
    }
}
Sapphira answered 22/8, 2014 at 2:26 Comment(0)
Z
4

This is definitely possible. At least now. The answer can be seen on https://gist.github.com/rciovati/8461832 at the bottom.

apply plugin: 'findbugs'

// android configuration

findbugs {
    sourceSets = []
    ignoreFailures = true
}

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("../config/findbugs/exclude.xml")

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

check.doLast {
    project.tasks.getByName("findbugs").execute()
}

The important part here is dependsOn: assembleDebug. Without that you will get a No classes configured for FindBugs analysis error message.

Refer to this https://mcmap.net/q/1171366/-eclipse-findbugs-exclude-filter-files-doesn-39-t-work for the exclude file.

Zygotene answered 26/7, 2015 at 0:29 Comment(1)
I missed dependsOn and got the same issue when I first cleaned. Thanks!Archimandrite
Z
2

I was able to solving the problem

by adding find bug as separate task

 task findbugs(type: FindBugs) {
    ignoreFailures = true
    classes = fileTree('build/classes/debug/')
    source = fileTree('src/main/java/')
    classpath = files()
   effort = 'max'
 }

this task can run using

gradle findbugs

If you are using android-test plugin you have to exclude findbugsTestDebug task when build.

gradle build -x  findbugsTestDebug
Zacharia answered 13/12, 2013 at 3:56 Comment(1)
Note that this works fine if you don't use any other source folders, or flavors, or build types. My answer below about the lack of integration is about a true integration that works no matter how you configure your android project and no matter where your code lives (in the main source sets, in the flavor sourcesets, etc...)Mahout
S
0

I have to specify the default sourceSet for findbugs. Initially it wasnt there so I was getting the error.

    findbugs {
    sourceSets = []    //Default sourceSet
    toolVersion = "3.0.1"      
    ignoreFailures = true      
    reportsDir = file("$project.buildDir/findbugsReports")
    effort = "max"
    reportLevel = "low"
}
Southsoutheast answered 7/3, 2017 at 15:30 Comment(0)
H
0

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.

Hobnob answered 27/9, 2019 at 7:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.