[英]Android - set all lint warnings as errors except for certain ones
當引入lint-baseline.xml
文件中沒有的新的lint警告時,我試圖使我的持續集成失敗。 我想將所有棉絨警告都視為錯誤(因此構建被中止),但是我想要一種方法,將某些棉絨檢查指定為信息或警告級別,以便它們仍出現在棉絨結果中,但不要不會導致構建中止。
這是一個基本我想做的例子(除非這不起作用,如果存在任何不可忽略的警告,構建將失敗):
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多個皮棉檢查設置為錯誤級別,但這並不能證明將來,因為每次添加新的皮棉檢查時,我都必須更新列表。
如果不使用Gradle lintOptions
( checkAllWarnings
, warningsAsErrors
等)來配置應將哪些警告視為錯誤,則應該能夠實現所需的目標。 請改用lint.xml。 在那里,您可以執行以下操作:
<?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對其進行過測試,但是我認為沒有理由不應該在這里使用它。
從此文檔看來,信息性不是真正的選擇,我建議:
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', ...
}
}
對我而言,此配置有效:
android {
lintOptions {
warningsAsErrors true
warning 'MissingTranslation', ...
}
}
看來這些選項是按照“正確的順序”(也就是“我需要的”)進行評估的,即首先將所有警告提升為錯誤,然后再次為單個問題ID覆蓋此設置。 使用warning
而不是disable
或ignore
可確保問題在報告或IDE中仍然可見。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.