13

I am trying to make my continuous integration fail the build when new lint warnings that aren't in the lint-baseline.xml file are introduced. I want to have all lint warnings treated as errors (so the build is aborted), but I'd like a way to specify certain lint checks to be treated as informational or warning level so that they still appear in the lint results, but don't cause the build to be aborted.

Here is an example of basically what I'd like to do (except this doesn't work, the build fails if any non-ignored warnings exist):

lintOptions {
    lintConfig file("lint.xml")
    baseline file("lint-baseline.xml")
    checkAllWarnings true
    warningsAsErrors true
    abortOnError true
    informational 'MissingTranslation, ...' // don't fail the build for these
}

Is there an easy way to treat all lint checks as errors, excluding certain ones? I thought about manually setting all 200+ lint checks to the error level, but that wouldn't be very future proof, since I'd have to update the list every time new lint checks were added.

starkej2
  • 11,391
  • 6
  • 35
  • 41

3 Answers3

7

You should be able to achieve what you want if you do not use the Gradle lintOptions (checkAllWarnings, warningsAsErrors, etc.) to configure which warnings should be treated as errors. Use lint.xml instead. There you can do the following:

<?xml version="1.0" encoding="UTF-8"?>
<lint>
   <issue id="MissingTranslation" severity="warning" />

   <!-- The following must be at the bottom of your file!
        All lint issues (not listed above) will be treated as errors. -->
   <issue id="all" severity="error" />
</lint>

In my tests this seemed to work fine and all warnings were treated as errors except for those listed at the top of the lint.xml. However, I've not tested it in combination with a lint-baseline.xml but I see no reason why it shouldn't work there as well.

Araxias
  • 104
  • 2
  • 4
3

For me, this configuration worked:

android {
    lintOptions {
        warningsAsErrors true
        warning 'MissingTranslation', ...
    }
}

It seems the options are evaluated in the "correct order" (aka "as I need it"), i.e. first all warnings are elevated to errors, then this settings is overriden again for a single issue id. Using warning instead of disable or ignore ensures the issues are still visible in the report or the IDE.

tommi
  • 84
  • 3
2

It doesnt seem informational is a real option from this doc, I suggest:

android {
    lintOptions {
        checkAllWarnings true
        warningsAsErrors true
        // use this line to check all rules except those listed
        disable 'MissingTranslation', ...
        //OR this line to check but not worry about result (i think this is what you want)
        ignore 'MissingTranslation', ...
    }     
}
Nick Cardoso
  • 20,807
  • 14
  • 73
  • 124
  • The problem is I want the warnings to still be flagged in the IDE and if possible, also in the Android studio inspection results. Looking for a way to have the continuous integration builds fail when new lint warnings are introduced, with the ability to designate certain warnings that shouldn't fail the build. I don't want these warnings to be completely ignored or disabled though. – starkej2 Mar 17 '17 at 17:33
  • Ignore seems to be a weaker version of disable - it runs but wont fail the build, thus should still log. is that not good enough with log all tests switched on? Or have I got the meaning of ignore wrong? – Nick Cardoso Mar 17 '17 at 20:26
  • I think ignore prevents the lint check from running. I don't see ignored lint warnings in Android Studio or lint results. – starkej2 Mar 20 '17 at 18:44
  • android { lintOptions { // set to true to turn off analysis progress reporting by lint quiet true // if true, stop the gradle build if errors are found abortOnError false // if true, only report errors ignoreWarnings true } } – Jigar Patel Mar 22 '17 at 04:12