この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
まえがき
前回のAndroid Studioに静的分析ツールFindBugsを追加して品質を高める | Developers.IOでは、Android StudioからFindBugsを実行しました。
今回はCIなどでも確認できるように、コマンドラインから実行できるようにします。
設定
app/build.gradle
apply plugin: 'com.android.application'
+ apply plugin: 'findbugs'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.kamedon.sampleapp"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
}
+ task findbugs(type: FindBugs) {
+ ignoreFailures = true
+ classes = fileTree('build/intermediates/classes/debug/')
+ source = fileTree('src/main/java/')
+ classpath = files()
+ effort = 'max'
+ reportLevel = "low" // *どのレベルの報告まで対応するかで変更*
+ excludeFilter = new File("${project.rootDir}/findbugs-filter.xml")
+ }
// html出力の方が見やすいため
+ tasks.withType(FindBugs) {
+ reports {
+ xml.enabled = false
+ html.enabled = true
+ }
+ }
コマンド
あくまでも、ビルド後に解析ができるようになるので
./gradlew assembleDebug findbugs
ビルド済みの場合はfindbugsだけで大丈夫です。
./gradlew findbugs
ここに作られます。
app/build/reports/findbugs/findbugs.html