patrickfav/under-the-hood

View on GitHub
gradle/checkstyle.gradle

Summary

Maintainability
Test Coverage
/*
 *  Copyright 2016 Patrick Favre-Bulle
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * Checkstyle tasks
 * Usage:
 * - place this file under root dir of your project at /gradle  directory
 * - apply script from your gradle file:
 * apply from : "{rootDir}/gradle/checkstyle.gradle"
 *
 * To configure checkstyle use configs at:
 * "{rootDir}/config/checkstyle/checkstyle.xml" - for main projects
 * "{rootDir}/config/checkstyle/checkstyle-test.xml" - for tests
 * "{rootDir}/config/checkstyle/suppresions.xml" - for style suppressions
 *
 * Xml and HTML reports are stored:
 * "{project.buildDir}/reports/checkstyle/"
 * HTML styling is done by XSLT stylesheet:
 * "{rootDir}/config/checkstyle/checkstyle-noframes-sorted.xsl"
 */

apply plugin: 'checkstyle'

checkstyle {
    toolVersion = "8.18"
}

task checkstyleMain(type: Checkstyle) {
    ignoreFailures = false
    showViolations = false
    source fileTree(dir: 'src', exclude: ['**/*test*/**', '**/*Test*/**'])
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'
    classpath = files()
    configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
}

task checkstyleTest(type: Checkstyle) {
    ignoreFailures = false
    showViolations = false
    source fileTree(dir: 'src', include: ['**/*test*/**', '**/*Test*/**'])
    include '**/*.java'
    exclude '**/gen/**'
    exclude '**/R.java'
    exclude '**/BuildConfig.java'
    classpath = files()
    configFile = file("${rootProject.rootDir}/config/checkstyle/checkstyle.xml")
}

task checkstyle(dependsOn: ['checkstyleMain', 'checkstyleTest']) {
    description 'Runs Checkstyle inspection against Android sourcesets.'
    group = 'Code Quality'
}