2015-03-06 33 views
7

Tôi có thể thiết lập PMD, Findbugs và công cụ phân tích mã tĩnh Checkstyle cho một dự án Android bằng phiên bản mới nhất của gradle như thế nào? Tôi đã thử nhiều thứ nhưng tôi không thể làm cho chúng hoạt động được.PMD, checkstyle và findbugs android setup

Cảm ơn

+0

Bạn có nhận được bất kỳ giải pháp cho điều này? –

+0

Bản sao có thể có của [Nhận plugin và trình kiểm tra gradle của Android hoạt động cùng nhau/sử dụng dòng lệnh] (https://stackoverflow.com/questions/17050654/get-android-gradle-plugin-checkstyle-working-together-command-line-usage) – tir38

Trả lời

6

Checkstyle/PMD

Có một plugin tốt đẹp bạn có thể sử dụng cho checkstyle và PMD. Chỉ cần thêm

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

để gradle.build toàn cầu của bạn và sử dụng nó trong mô-đun của bạn (s) như sau:

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

hoặc bất kỳ của các cấu hình này:

// 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 bạn có thể tìm thấy trang chủ và mã nguồn của plugin.

FindBugs

// Cập nhật: //

Plugin mới nhất của noveogroup (1.2.3) bây giờ cũng hỗ trợ FindBugs. Vì vậy, bạn có thể tùy chỉnh nó theo cùng một cách như checkstyle hay 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. 
} 

// CẬP NHẬT END //

Tôi chạy FindBugs kiểm tra với đoạn script gradle sau đó bạn thêm vào build.gradle của mô-đun của bạn :

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 

exclude.xml của tôi trông giống như sau:

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

whe reas kiểm tra cuối cùng được sử dụng để bỏ qua các lớp học được tạo ra bởi AndroidAnnotations và nhiều khả năng bạn sẽ không sử dụng việc kiểm tra này ...

Sau đó tôi có thể chạy các nhiệm vụ do

./gradlew customFindbugs 
// or it is also included in the build task like the checks, too 
./gradlew build 
Các vấn đề liên quan