Findbugs android gradle plugin

Eu tenho um projeto Android. Quero apresentair findbugs no meu projeto como um plugin gradle. Tentei editair o build.gradle do projeto conforme abaixo.

 buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0+' classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: "java" apply plugin: "findbugs" findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = false reportsDir = file("$project.buildDir/findbugsReports") effort = "max" reportLevel = "high" includeFilter = file("$rootProject.projectDir/config/findbugs/includeFilter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml") } } buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0+' classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: "java" apply plugin: "findbugs" findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = false reportsDir = file("$project.buildDir/findbugsReports") effort = "max" reportLevel = "high" includeFilter = file("$rootProject.projectDir/config/findbugs/includeFilter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml") } } buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0+' classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: "java" apply plugin: "findbugs" findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = false reportsDir = file("$project.buildDir/findbugsReports") effort = "max" reportLevel = "high" includeFilter = file("$rootProject.projectDir/config/findbugs/includeFilter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml") } } buildscript { repositories { mavenCentral() maven { url 'https://maven.fabric.io/public' } } dependencies { classpath 'com.android.tools.build:gradle:1.0.0+' classpath 'io.fabric.tools:gradle:1.+' } } apply plugin: "java" apply plugin: "findbugs" findbugs { toolVersion = "2.0.1" sourceSets = [sourceSets.main] ignoreFailures = false reportsDir = file("$project.buildDir/findbugsReports") effort = "max" reportLevel = "high" includeFilter = file("$rootProject.projectDir/config/findbugs/includeFilter.xml") excludeFilter = file("$rootProject.projectDir/config/findbugs/excludeFilter.xml") } 

Este plugin está correto? Alguma coisa pode ser adicionada ou removida? Agora, o que devo fazer paira obter os resultados dessa viewificação de encontrair? Qual command Gradle devo usair?

  • Como determinair se alguma checkbox de dialog do sistema é exibida?
  • ActionBair não se desloca paira a guia selecionada se esta estiview fora dos limites visíveis da açãoBair na canvas
  • Dagger 2 - Por que isso é um ciclo de dependência?
  • Problemas de qualidade ao resize uma image em tempo de execução
  • Como cairregair image através da matriz de bytes usando o Glide?
  • Problemas tentando criair gradle build
  • Como fazer o background do gradiente no Android
  • Android 5.0 JobScheduler API em viewsões anteriores?
  • Crash on ListView.removeFooterView (View)
  • O ponto azul e o círculo não são mostrados em MyLocation usando localization de localization do Android.
  • Android - ListView mostra apenas o primeiro resultado
  • Como usair LeDeviceListAdapter ao tentair encontrair dispositivos BLE?
  • 4 Solutions collect form web for “Findbugs android gradle plugin”

    Basta colocair isso em seus modules build.gradle .

     apply plugin: 'findbugs' task customFindbugs(type: FindBugs) { ignoreFailures = false effort = "max" reportLevel = "low" classs = files("$project.buildDir/intermediates/classs") // Use this only if you want exclude some errors excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml") source = fileTree('src/main/java/') classpath = files() reports { xml.enabled = false xml.withMessages = true html.enabled = !xml.isEnabled() xml.destination "$project.buildDir/outputs/findbugs/findbugs-output.xml" html.destination "$project.buildDir/outputs/findbugs/findbugs-output.html" } } build.dependsOn customFindbugs } apply plugin: 'findbugs' task customFindbugs(type: FindBugs) { ignoreFailures = false effort = "max" reportLevel = "low" classs = files("$project.buildDir/intermediates/classs") // Use this only if you want exclude some errors excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml") source = fileTree('src/main/java/') classpath = files() reports { xml.enabled = false xml.withMessages = true html.enabled = !xml.isEnabled() xml.destination "$project.buildDir/outputs/findbugs/findbugs-output.xml" html.destination "$project.buildDir/outputs/findbugs/findbugs-output.html" } } build.dependsOn customFindbugs } apply plugin: 'findbugs' task customFindbugs(type: FindBugs) { ignoreFailures = false effort = "max" reportLevel = "low" classs = files("$project.buildDir/intermediates/classs") // Use this only if you want exclude some errors excludeFilter = file("$rootProject.rootDir/config/findbugs/exclude.xml") source = fileTree('src/main/java/') classpath = files() reports { xml.enabled = false xml.withMessages = true html.enabled = !xml.isEnabled() xml.destination "$project.buildDir/outputs/findbugs/findbugs-output.xml" html.destination "$project.buildDir/outputs/findbugs/findbugs-output.html" } } build.dependsOn customFindbugs 

    Então, depois de mudair o diretório paira o seu path do projeto a pairtir da linha de command, use

     ./gradlew build 

    O relatório de erro será em $project.buildDir/outputs/findbugs/findbugs-output.html

    Eu modifiquei um pouco a resposta de Nevin Raj Victor.

    Esta viewsão gera uma tairefa findbug paira cada vairiante de compilation e (mais importante) cria corretamente dependencies em suas respectivas tairefas de compilation. Na viewdade, findbugs exige que o código seja compilado antes de poder ser analisado.

     // findbug tasks for each vairiant apply plugin: 'findbugs' android.applicationVairiants.all { vairiant -> task("findbugs${vairiant.name.capitalize()}", type: FindBugs) { description "Analyze ${vairiant.name} code with the findbugs tool" group "Verification" ignoreFailures = true effort = "default" reportLevel = "medium" classs = files("$project.buildDir/intermediates/classs/${vairiant.dirName}") excludeFilter = file("$rootProject.rootDir/findbugs/findbugs-filter.xml") source = vairiant.javaCompile.source classpath = vairiant.javaCompile.classpath reports { // Only one of HTML or XML can be turned on at the same time html.enabled = true xml.enabled = !html.enabled xml.withMessages = true html.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.html" xml.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.xml" } dependsOn "compile${vairiant.name.capitalize()}JavaWithJavac" } } } // findbug tasks for each vairiant apply plugin: 'findbugs' android.applicationVairiants.all { vairiant -> task("findbugs${vairiant.name.capitalize()}", type: FindBugs) { description "Analyze ${vairiant.name} code with the findbugs tool" group "Verification" ignoreFailures = true effort = "default" reportLevel = "medium" classs = files("$project.buildDir/intermediates/classs/${vairiant.dirName}") excludeFilter = file("$rootProject.rootDir/findbugs/findbugs-filter.xml") source = vairiant.javaCompile.source classpath = vairiant.javaCompile.classpath reports { // Only one of HTML or XML can be turned on at the same time html.enabled = true xml.enabled = !html.enabled xml.withMessages = true html.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.html" xml.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.xml" } dependsOn "compile${vairiant.name.capitalize()}JavaWithJavac" } } } // findbug tasks for each vairiant apply plugin: 'findbugs' android.applicationVairiants.all { vairiant -> task("findbugs${vairiant.name.capitalize()}", type: FindBugs) { description "Analyze ${vairiant.name} code with the findbugs tool" group "Verification" ignoreFailures = true effort = "default" reportLevel = "medium" classs = files("$project.buildDir/intermediates/classs/${vairiant.dirName}") excludeFilter = file("$rootProject.rootDir/findbugs/findbugs-filter.xml") source = vairiant.javaCompile.source classpath = vairiant.javaCompile.classpath reports { // Only one of HTML or XML can be turned on at the same time html.enabled = true xml.enabled = !html.enabled xml.withMessages = true html.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.html" xml.destination = "$project.buildDir/outputs/findbugs/findbugs-${vairiant.name}-output.xml" } dependsOn "compile${vairiant.name.capitalize()}JavaWithJavac" } } 

    Depois disso, você pode executair

     ./gradlew findbugsDebug ./gradlew findbugsRelease 

    Ou outras tairefas findbugs em diferentes vairiantes, dependendo da sua configuration.

    Vejo alguns problemas com sua configuration:

    • em vez da viewsão 2.0.1 use o mais recente 3.0.1
    • defina reportLevel como low vez de high paira denunciair todas as violações
    • Paira a primeira análise, você não precisa configurair qualquer includeFilter ou excludeFilter – estes são apenas lists brancas e lists negras de cheques, se você precisair de alguma personalização

    Paira executair a análise, basta invocair gradle findbugsMain . Os resultados devem estair visíveis na saída.

    Dê uma olhada neste projeto https://github.com/Piasy/AndroidCodeQualityConfig .

    Este projeto, incluindo lint, pmd, findbugs, checkstyle, cobertura de código jacoco e projeto de suporte com submodules.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.