정적 코드 분석은 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 이전에는 SpotBugs 대신 FindBugs가 사용되었습니다.
정적 코드 분석을 구성하는 것은 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 이전에는 SpotBugs 대신 FindBugs가 사용되었습니다. 이전 버전을 사용하는 경우 DSL은 동일하지만 모든 속성에 대한 spotbugs 대신 findbugs 사용합니다.
모든 v2.x findbugs dsl 속성은 더 쉽게 업그레이드하기 위해 V3.X의 Spotbugs에 자동으로 매핑됩니다.
PMD, SpotBugs 및 CheckStyle에서 사용하는 규칙은 sourceSetConfig 블록에서 소스마다 재정의 할 수 있습니다.
맞춤형 보풀 규칙을 포함하려면 androidLint 의 종속성으로 항아리를 단순히 포함시킬 수 있습니다. 예를 들어, Monits 'Android Linters를 추가하여 다음을 포함시킬 수 있습니다.
dependencies {
androidLint ' com.monits:android-linters:1.+ '
}플러그인은 다음과 같은 작업을 추가합니다.
cpdcheckstyle 은 다음에 따라 다릅니다.checkstyleSourcesetname 작업 ( checkstyleMain , checkstyleTest 등).spotbugs 는 다음에 따라 다릅니다.spotbugsSourcesetname 작업 ( spotbugsMain , spotbugsTest 등).pmd 는 다음에 따라 다릅니다.pmdSourcesetname 작업 ( pmdMain , pmdTest 등). 버전 3.0.0 이전에는 SpotBugs 대신 FindBugs가 사용되었습니다. 기존 findbugs* 작업은 여전히 사용 가능하며 해당 spotbugs* 작업에 매핑됩니다.
모든 작업은 Java 플러그인의 check 작업의 일부로 실행되도록합니다.
항상 어떤 모양이나 형태로든 자유롭게 기여할 수 있듯이 귀하의 의견을 기대합니다!.
보고 된 것들을보고 있다면 두 가지 중 하나 일 수 있다고 생각하지 않아야합니다.
모든 도구에는 자체 억제 메커니즘이 있으므로 문서를 참조해야합니다.
@SupressFBWarnings javadocCopyright 2010-2017 MONITS SA
Apache 라이센스, 버전 2.0 ( "라이센스")에 따라 라이센스가 부여되었습니다. 라이센스를 준수하는 것 외에는이 작업을 사용할 수 없습니다. 다음에서 라이센스 사본을 얻을 수 있습니다.
http://www.apache.org/licenses/license-2.0