Android-将所有棉绒警告设置为错误(某些警告除外) [英] Android - set all lint warnings as errors except for certain ones

查看:171
本文介绍了Android-将所有棉绒警告设置为错误(某些警告除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当引入lint-baseline.xml文件中没有的新棉绒警告时,我试图使我的持续集成失败.我想将所有棉绒警告都视为错误(因此构建被中止),但是我想要一种方法来指定将某些棉绒检查视为信息或警告级别,以便它们仍出现在棉绒结果中,但不要不会导致构建中止.

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
}

是否有一种简单的方法将所有皮棉检查视为错误,但不包括某些错误?我曾考虑过手动将所有200多个皮棉检查设置为错误级别,但这并不能保证将来,因为每次添加新的皮棉检查时我都必须更新列表.

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.

推荐答案

如果不使用Gradle lintOptions(checkAllWarningswarningsAsErrors等)进行配置,则应该能够实现所需的功能哪些警告应视为错误.请改用lint.xml.在那里,您可以执行以下操作:

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>

在我的测试中,这似乎运行良好,并且所有警告都被视为错误,但lint.xml顶部列出的警告除外. 但是,我尚未将它与lint-baseline.xml结合使用进行测试,但我认为没有理由也不能在这里使用它.

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.

这篇关于Android-将所有棉绒警告设置为错误(某些警告除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆