Search code examples
javaandroidgradlestatic-code-analysisspotbugs

how to create a custom task using spotbugs to run static code analysis in gradle?


Im trying to create custom spotbugs task to do static code analysis. since its big project. while in execution, gradle throws out some errors and ultimately leading to build failure.

My custom task :


apply plugin: "com.github.spotbugs-base"

task customSpotbugs (type: com.github.spotbugs.snom.SpotBugsTask) {
    ignoreFailures = true
    effort = "default"
    reportLevel = "medium"
    classes = files("$project.buildDir/intermediates/javac/dxRelease/compileDxReleaseJavaWithJavac/classes")
    excludeFilter = file("$rootProject.rootDir/exclude.xml")
    reports {
        xml.enabled = false
        html.enabled = true
        html {
            stylesheet = 'fancy-hist.xsl'
        }
    }
}

dependencies {
    spotbugs 'com.github.spotbugs:spotbugs:4.0.0'
    spotbugsPlugins 'com.h3xstream.findsecbugs:findsecbugs-plugin:1.7.1'
}

ERRORS:

The following classes needed for analysis were missing:
  androidx.room.EntityDeletionOrUpdateAdapter
  androidx.room.SharedSQLiteStatement
  androidx.room.EntityInsertionAdapter
..........
> Task :Domain:customSpotbugs FAILED
:Domain:customSpotbugs (Thread[Execution worker for ':' Thread 8,5,main]) completed. Took 2 hrs 0 mins 12.064 secs.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Domain:customSpotbugs'.
> A failure occurred while executing com.github.spotbugs.snom.internal.SpotBugsRunnerForWorker$SpotBugsExecutor
   > Verification failed: SpotBugs execution thrown exception

* Try:
Run with --stacktrace option to get the stack trace. Run with --debug option to get more log output. Run with --scan to get full insights.

as there are very less documentation about this, any help would be highly appreciated.. thank you


Solution

  • I increased heapsize from 1g to 2g and changed version for spotbugs 'com.github.spotbugs:spotbugs:4.0.0' from 4.0.0 to 4.1.1. it fixed my issue.