novoda / gradle-static-analysis-plugin

Easy setup of static analysis tools for Android and Java projects.
Apache License 2.0
410 stars 28 forks source link

analysis not running after adding build flavors to app modules #229

Closed stealthrabbi closed 4 years ago

stealthrabbi commented 4 years ago

I have a static-analysis.gradle file similar to the example projects. Since adding build flavors, analysis isn't running on my app module for checkstyle, pmd, and spotbugs. It does run lint. Analysis is still running fully on other library modules I have in my multi-module project. I can't tell if it's somethign with my includeVariants or something else I need to do in the app module. Is there an example of how to use this plugin with build flavors? How do I know what my variants are?


    checkstyle {
        // upgrading the tools version is very finicky. e.g. changing to the latest causes
        // the checkstyles task itself to fail itself without much info
        toolVersion '8.32'
        configFile rootProject.file('config/google-checkstyles.xml')
        includeVariants { variant -> variant.name.contains('debug') }
    }

    pmd {
        toolVersion '6.23.0'
        incrementalAnalysis = true
        ruleSetFiles = rootProject.files('config/pmd-rules.xml')
        ruleSets = [] // https://stackoverflow.com/questions/32247190/pmd-exclude-pattern-with-gradle
        includeVariants { variant -> variant.name.contains('debug') }
    }

    spotbugs {
        excludeFilter rootProject.file('config/findbugs-excludes.xml')
        includeVariants { variant -> variant.name.contains('debug') }
    }

    // android lint errors resolved, but warnings still remain. Disable this until all warnings are resolved
    lintOptions {
        lintConfig rootProject.file('config/android-lint.xml')
        checkReleaseBuilds false
        warningsAsErrors false
    }

flavor config:

    productFlavors {

        flavorDimensions "configuration"
        item1 {
            getIsDefault().set(true)
            dimension "configuration"
            versionNameSuffix "Item1"
        }
        item2 {
            dimension "configuration"
            versionNameSuffix "Item2"
        }
    }
stealthrabbi commented 4 years ago

I tried changing to variant.name.contains('item1Debug`), since that's what a :AndroidApp:lint reports as variants, but that did not work.

stealthrabbi commented 4 years ago

it seems that doing a variant filter on ebug works to pick up capitalized Debug for moduels with flavors, and also includes debug builds for non-flavored modules. Or I can just remove the variant inclusion stuff completely. Is that the right way to do this?

tasomaniac commented 4 years ago

If you remove variant filter, then the checks are going to run for all variants. This will essentially take much more time. If you're ok with checking only 1 variant, the execution will be faster. Keep in mind that checking only 1 variant can also cause issues being missed in the 2nd variant of their code is too diverged.

includeVariants takes a predicate. It is up to you to decide how are you going to filter. Variant is the official Android Gradle plugin variants. Apart from name, there should be other properties coming from variant that you can use to filter (e.g debuggable == true)