2015-03-06 13 views
7

Jak mogę skonfigurować narzędzia analizy kodu PMD, Findbugs i Checkstyle dla projektu Android przy użyciu najnowszej wersji gradle? Próbowałem kilku rzeczy, ale nie udaje mi się ich sprawić.PMD, checkstyle i findbugs ustawienia Androida

Dzięki

+0

Czy któryś rozwiązanie tego? –

+0

Prawdopodobny duplikat [Get Android gradle plugin & checkstyle working together/use linii poleceń] (https://stackoverflow.com/questions/17050654/get-android-gradle-plugin-checkstyle-working-together-command-line-usage) – tir38

Odpowiedz

6

Checkstyle/PMD

Jest miły wtyczki można używać do Checkstyle i PMD. Wystarczy dodać

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' 
    } 
} 

do globalnej gradle.build i używać go w module (s) jak następuje:

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" 
    } 
} 

lub którykolwiek z tych konfiguracjach:

// 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 ci może znaleźć stronę główną wtyczki i kod źródłowy.

Findbugs

// UPDATE //

najnowszą wtyczkę przez noveogroup (1.2.3) wspiera teraz także findbugs. Dzięki czemu można dostosować go w ten sam sposób jak Checkstyle lub 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 //

uruchomić findbugs sprawdzić w poniższym fragmencie Gradle skryptu którego dodać do swojego modułu build.gradle :

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 

Moja exclude.xml wygląda następująco:

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

trakt REAS ostatnia kontrola jest używana do pominięcia klas generowanych przez AndroidAnnotations i najprawdopodobniej nie będzie wykorzystywać tę kontrolę ...

Po tym jestem w stanie uruchomić zadanie

./gradlew customFindbugs 
// or it is also included in the build task like the checks, too 
./gradlew build 
Powiązane problemy