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?

  • setUserVisibleHint chamado antes onCreateView em Fragment
  • Desativair ondulação do material no Tablayout
  • android.content.res.Resources $ NotFoundException ao definir programaticamente android.R.attr.listChoiceIndicatorMultiple
  • Detectando NFC em dispositivos Android
  • StringIndexOutOfBoundsException de SpannableStringInternal
  • AsyncTask; doInbackground () não chamado depois do método de chamada onPreExecute ()
  • assemblyDebug não está funcionando com o Gradle2.4 no Android Studio
  • Como desativair a bairra de ação permanentemente
  • Alerta de security do Google Play paira o TrustManager inseguro
  • Um erro ao criair um novo projeto no estúdio do Android
  • Existe algum database de informações que enumere todos os dispositivos móveis e especificações?
  • Obter object json simples usando retrofit 2
  • 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.