Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate findbugs reports using gradle script?

I am trying to generate reports using findbugs plugin for that i wrote below mentioned gradle script.I am setting the destination folder for reports but respective folder not get generated.So, how to solve this issue.

I can able to generate reports manually by using export button but i want generate from the gradle script.

Is it possible to generate reports from gradle script?

my gradle version - 2.2.1

task findbugs(type: FindBugs) {
    ignoreFailures = true
    effort = "max"
    reportLevel = "high"
    classes = files("${project.buildDir}/findbugs")
    source 'src'
    include '**/*.java'
    exclude '**/gen/**'

    reports {
        xml.enabled = true
        xml {
            destination "$project.buildDir/reports/findbugs/findbugs.xml"
            xml.withMessages true
        }
    }
    classpath = files()
}
like image 593
Boopathi Avatar asked Mar 24 '15 10:03

Boopathi


1 Answers

I managed to get to run findbugs with the newest gradle with the following gradle script snippet:

apply plugin: 'findbugs'

task customFindbugs(type: FindBugs) {
    ignoreFailures = true
    effort = "default"
    reportLevel = "medium"
    classes = files("$project.buildDir/intermediates/classes")
    excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml")

    source = fileTree('src/main/java/')
    classpath = files()
    reports {
        xml.enabled = false
        xml.withMessages = true
        html.enabled = !xml.isEnabled()
        xml.destination "$project.buildDir/outputs/findbugs/findbugs-output.xml"
        html.destination "$project.buildDir/outputs/findbugs/findbugs-output.html"
    }
}
// UPDATE: renamed the task to customFindbugs and made it automatically be called when build is called
build.dependsOn customFindbugs

My exclude.xml looks like the following:

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

whereas the last check is used to omit classes generated by AndroidAnnotations and you most likely won't use this check...

After that I'm able to run the task by

./gradlew customFindbugs

or since the update of my code just by

./gradlew build
like image 97
luckyhandler Avatar answered Oct 23 '22 07:10

luckyhandler