2015-03-06 16 views
7

Come posso impostare gli strumenti di analisi del codice statico PMD, Findbugs e Checkstyle per un progetto Android utilizzando l'ultima versione di gradle? Ho provato diverse cose ma non riesco a farle funzionare.PMD, checkstyle e findbugs configurazione Android

Grazie

+0

Hai avuto alcun soluzione per questo? –

+0

Possibile duplicato di [Ottieni il plugin gradle Android e il checkstyle funzionanti insieme/l'utilizzo dalla riga di comando] (https://stackoverflow.com/questions/17050654/get-android-gradle-plugin-checkstyle-working-together-command-line-usage) – tir38

risposta

6

Checkstyle/PMD

C'è un bel plugin è possibile utilizzare per checkstyle e PMD. Basta aggiungere

buildscript { 
    repositories { 
     // ... 
    } 
    dependencies { 
     // ... 
     classpath 'com.android.tools.build:gradle:1.2.3' 

     // Enables checkStyle and pmd gradle support for android modules 
     classpath 'com.noveogroup.android:check:1.1.2' 
    } 
} 

al vostro gradle.build globale e utilizzarlo nella vostra modulo (s) come la seguente:

apply plugin: 'com.noveogroup.android.check' 

check { 
    abortOnError false 
    checkstyle { 
     config "$rootProject.rootDir/path/to/your/checkstyle.xml" 
    } 
    pmd { 
     config "$rootProject.rootDir/path/tp/your/pmd-ruleset.xml" 
    } 
} 

o qualsiasi di queste configurazioni:

// configuration is optional 
check { 
    // skip source code checking or not, false by default 
    skip true/false 
    // fails build if code style violation is found, false by default 
    abortOnError true/false 

    checkstyle { 
     // skip Checkstyle, false by deafult 
     skip true/false 
     // fails build if Checkstyle rule violation is found, false by default 
     abortOnError true/false 
     // configuration file 
     config project.file('path/to/checkstyle.xml') 
     // configuration resource 
     // see http://gradle.org/docs/2.2/release-notes#sharing-configuration-files-across-builds 
     config resources.text.fromFile(someTask) 
     // configuration path 
     config 'path/to/checkstyle.xml' 
     // predefined configurations: easy and hard 
     config easy() 
     config hard() 
     // plugin find configuration file in project.file('config/checkstyle.xml') by default 
     // if there are no configuration file, easy() configuration will be used 
    } 

    pmd { 
     // the same configuration as for Checkstyle 
     // plugin find configuration file in project.file('config/pmd.xml') by default 
     // if there are no configuration file, easy() configuration will be used 
    } 
} 

Here voi può trovare la homepage del plugin e il codice sorgente.

Findbugs

// // UPDATE

L'ultimo plugin noveogroup (1.2.3) ora supporta anche findbugs. Quindi è possibile personalizzare lo stesso senso come checkstyle o PMD:

// configuration of FindBugs checker 
findbugs { 
    // the same configuration as for Checkstyle 

    // by default plugin finds configuration file in <rootProject>/config/findbugs.xml, 
    // after that in <project>/config/findbugs.xml and if there are no configuration 
    // file, easy() configuration will be used. 
} 

// UPDATE END //

corro i findbugs verificare con il seguente frammento di script Gradle che si aggiunge alla build.gradle del modulo :

apply plugin: 'findbugs' 

task customFindbugs(type: FindBugs) { 
    ignoreFailures = true 
    effort = "default" 
    reportLevel = "medium" 
    classes = files("$project.buildDir/intermediates/classes") 
    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" 
    } 
} 
// UPDATE: renamed the task to customFindbugs and made it automatically be called when build is called 
build.dependsOn customFindbugs 

mio exclude.xml è simile al seguente:

<FindBugsFilter> 
    <Match> 
     <Class name="~.*R\$.*"/> 
    </Match> 
    <Match> 
     <Class name="~.*Manifest\$.*"/> 
    </Match> 
    <Match> 
     <Class name="~.*_"/> 
    </Match> 
</FindBugsFilter> 

whe Reas l'ultimo controllo viene utilizzata per omettere le classi generate da AndroidAnnotations e molto probabilmente non userà questo controllo ...

Dopo che sono in grado di eseguire l'attività da

./gradlew customFindbugs 
// or it is also included in the build task like the checks, too 
./gradlew build 
Problemi correlati