spotbugs / spotbugs-gradle-plugin

https://plugins.gradle.org/plugin/com.github.spotbugs
Apache License 2.0
178 stars 68 forks source link

Could anyone can leave the demo of spotbugs used in android project? #471

Open pengcao1 opened 3 years ago

pengcao1 commented 3 years ago

Hi everyone:

As you can see in the title, Could anyone can leave the demo of spotbugs used in the android project?

In my view, the official doc is obscure,

eg:

  1. What's should we add in the ${root}build.gradle
  2. What's should we add in the ${root}app/build.gradle
jscancella commented 3 years ago

@pengcao1 I'm not sure we actually have one. I know most of us don't work on Android projects. But if someone does have an example, it would be great to submit a pull request!

ByteHamster commented 3 years ago

I recently added SpotBugs to AntennaPod. See the commit here: https://github.com/AntennaPod/AntennaPod/commit/3946f986d723f8579a33140bbe3c0d95182ecab1

Basically, it's pretty straight-forward. In the commit above, I added some hacky printing tasks to be easier to use on CI but something like the following in the main ${root}build.gradle should work:

buildscript {
    dependencies {
        ...
        classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.0"
    }
}

allprojects {
    apply plugin: 'com.github.spotbugs'

    spotbugs {
        effort = 'max'
        reportLevel = 'medium'
    }
}

You can then run it using ./gradlew :app:spotbugsDebug or (if you use build variants) ./gradlew :app:spotbugs[Variant]Debug. AntennaPod uses multiple modules where some have variants and some don't. For that, we just execute ./gradlew spotbugs[Variant]Debug spotbugsDebug to run the respective task for all modules automatically.