Get Android gradle plugin & checkstyle working together / command line usage

后端 未结 6 1726
礼貌的吻别
礼貌的吻别 2020-12-23 10:31

I\'m evaluating the ability of the new gradle-based build system to reproduce our current ant-based build process and, as a gradle beginner, I failed to get checkstyle runni

6条回答
  •  别那么骄傲
    2020-12-23 10:55

    I got pmd, findbugs, and checkstyle working with Gradle 1.12 android plugin 0.12.+ using the following script:

    apply plugin: 'checkstyle'
    apply plugin: 'findbugs'
    apply plugin: 'pmd'
    
    check.dependsOn 'checkstyle', 'findbugs', 'pmd'
    
    task checkstyle(type: Checkstyle) {
        configFile file("${project.rootDir}/config/quality/checkstyle/checkstyle.xml")
        source 'src'
        include '**/*.java'
        exclude '**/gen/**'
    
        classpath = files()
    }
    
    task findbugs(type: FindBugs) {
        ignoreFailures = true
        effort = "max"
        reportLevel = "high"
        excludeFilter = new File("${project.rootDir}/config/quality/findbugs/findbugs-filter.xml")
        classes = files("$project.buildDir/intermediates/classes/")
    
        source 'src'
        include '**/*.java'
        exclude '**/gen/**'
    
        reports {
            xml {
                destination "$project.buildDir/reports/findbugs/findbugs.xml"
                xml.withMessages true
            }
        }
    
        classpath = files()
    }
    
    task pmd(type: Pmd) {
        ruleSetFiles = files("${project.rootDir}/config/quality/pmd/pmd-ruleset.xml")
        ignoreFailures = true
        ruleSets = ["basic", "braces", "strings"]
    
        source 'src'
        include '**/*.java'
        exclude '**/gen/**'
    
        reports {
            xml.enabled = true
            html.enabled = false
        }
    }
    

    Running gradle build in command line will run all code quality plugins and generate xml reports in app/build/reports/ which are then ready to be viewed or parsed by CI tools.

提交回复
热议问题