Search code examples
androidgradlelintmodularandroid-lint

How to share Android lintOptions across modules


I am building a multi-module app and in each module I have lint settings as follows

android {
   ...
   lintOptions {
        quiet true
        abortOnError false
        warningsAsErrors true
   }
   ...
}

It is tedious to repeat such settings across all modules so I'm looking for a way to write it once and share it in all modules.

I know there is something like lint.xml but I believe it is not for these configurations. If it was not part of android block it can easily create something like lint.gradle and use apply from to link to that file from all modules. However since it is within android, I'm not sure if there is a way to do that?


Solution

  • You can have a .gradle file that contains lintOptions that you'd like to share, and on your module's build.gradle you could use apply from, for example, you can have android-module-base.gradle on your root directory, which contains the lintOptions you'd like to share:

    android {
    ...
        lintOptions {
            quiet true
            abortOnError false
            warningsAsErrors true
        }
    ...
    }
    

    Then on your module's build.gradle, put this line at the beginning:

    apply from: "$rootDir/android-module-base.gradle"