靜態代碼分析圍繞CheckStyle,Spotbugs,PMD和CPD,為封裝插件提供新功能和擴展,使使用它們更易於使用它們,並以最小的努力為您提供更好的結果。
開箱即用,只需應用您獲得的插件:
R.class和BuildConfig.class )我們在等級插件門戶網站上,因此您可以簡單地做:
plugins {
id ' com.monits.staticCodeAnalysis ' version ' 3.1.1 '
}或者,您也可以做
buildscript {
repositories {
maven {
url ' https://plugins.gradle.org/m2/ '
}
}
dependencies {
classpath ' com.monits:static-code-analysis-plugin:3.1.1 '
}
}
apply plugin : ' com.monits.staticCodeAnalysis '或者,直接來自Jcenter
buildscript {
repositories {
jcenter()
}
dependencies {
classpath ' com.monits:static-code-analysis-plugin:3.1.1 '
}
}
apply plugin : ' com.monits.staticCodeAnalysis ' | 插件版本 | Gradle版本 | Android Gradle插件版本 |
|---|---|---|
| 3.x | 5.6+ | 3.3.0+ |
| 2.6.12 | 2.3最多5.6.x | 1.1.x最高3.5.x |
在使用3.0.0版本之前,FindBugs被代替Spotbugs。
由於其DSL,配置靜態代碼分析非常簡單和直觀。您可以選擇要運行的封裝插件並設置其配置文件。這是一個快速示例
staticCodeAnalysis {
spotbugs = true
checkstyle = true
pmd = true
cpd = true
androidLint = true
ignoreErrors = true
// default rules
spotbugsExclude = " $p roject . rootProject . projectDir /config/spotbugs/excludeFilter.xml "
checkstyleRules = ' https://raw.githubusercontent.com/Monits/static-code-analysis-plugin/staging/defaults/checkstyle/checkstyle-cache.xml '
pmdRules = [ ' https://raw.githubusercontent.com/Monits/static-code-analysis-plugin/staging/defaults/pmd/pmd.xml ' ,
' https://raw.githubusercontent.com/Monits/static-code-analysis-plugin/staging/defaults/pmd/pmd-android.xml ' ]
androidLintConfig = ' https://raw.githubusercontent.com/Monits/static-code-analysis-plugin/staging/defaults/android/android-lint.xml '
sourceSetConfig {
test { // or the name of any other sourceset
// use a more relaxed ruleset
checkstyleRules = ' config/checkstyle/test-checkstyle.xml '
spotbugsExclude = ' config/spotbugs/test-spotbugs.xml '
pmdRules = [ ' config/pmd/test-pmd.xml ' ,
' https://raw.githubusercontent.com/Monits/static-code-analysis-plugin/staging/defaults/pmd/pmd-android.xml ' ]
}
}
}默認情況下,應用了所有插件,錯誤不會使構建失敗,並且將從此存儲庫的最新默認值中獲取規則和排除
在使用3.0.0版本之前,FindBugs被代替Spotbugs。如果使用舊版本,則DSL是等效的,但使用findbugs代替點spotbugs ,用於所有屬性。
所有v2.x FindBugs DSL屬性都會自動映射到v3.x中的斑點,以更輕鬆地升級
PMD,Spotbugs和CheckStyle使用的規則可以在sourceSetConfig塊下覆蓋。
要包含自定義棉絨規則,您可以簡單地將罐子作為androidLint依賴性。例如,您可以通過添加:
dependencies {
androidLint ' com.monits:android-linters:1.+ '
}該插件將添加以下任務:
cpdcheckstyle ,取決於:checkstyleSourcesetname任務( checkstyleMain , checkstyleTest ,等等)。spotbugs ,取決於:spotbugsSourcesetname任務( spotbugsMain , spotbugsTest等)。pmd ,取決於:pmdSourcesetname任務( pmdMain , pmdTest ,等等)。在使用3.0.0版本之前,FindBugs被代替Spotbugs。舊的findbugs*任務仍然可用,並映射到相應的spotbugs*任務
所有任務都掛鉤以作為Java插件的check任務的一部分運行。
一如既往,可以隨意以任何形式或形式做出貢獻,我們期待您的反饋!
如果您看到正在報告的事情,您認為應該不應該是兩件事之一:
由於每個工具都有自己的抑制機制,因此您應該參考其文檔:
@SupressFBWarnings Javadoc版權2010-2017 MONITS SA
根據Apache許可證(版本2.0(“許可”)獲得許可;除了符合許可外,您不得使用此工作。您可以在以下方式獲得許可證的副本:
http://www.apache.org/licenses/license-2.0