Check code style with Checkstyle
This commit is contained in:
parent
da2b059802
commit
819e52cab3
2 changed files with 229 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ apply plugin: 'com.android.application'
|
|||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
apply plugin: 'checkstyle'
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
|
@ -81,11 +82,54 @@ ext {
|
|||
icepickLibVersion = '3.2.0'
|
||||
stethoLibVersion = '1.5.0'
|
||||
markwonVersion = '4.2.1'
|
||||
checkstyleVersion = '8.31'
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
configFile rootProject.file('checkstyle.xml')
|
||||
ignoreFailures false
|
||||
showViolations true
|
||||
toolVersion = "${checkstyleVersion}"
|
||||
}
|
||||
|
||||
task runCheckstyle(type: Checkstyle) {
|
||||
source 'src'
|
||||
include '**/*.java'
|
||||
exclude '**/gen/**'
|
||||
exclude '**/R.java'
|
||||
exclude '**/BuildConfig.java'
|
||||
exclude 'main/java/us/shandian/giga/**'
|
||||
exclude 'main/java/org/schabi/newpipe/streams/**'
|
||||
|
||||
// empty classpath
|
||||
classpath = files()
|
||||
|
||||
showViolations true
|
||||
|
||||
reports {
|
||||
xml.enabled true
|
||||
html.enabled true
|
||||
}
|
||||
}
|
||||
|
||||
tasks.withType(Checkstyle).each {
|
||||
checkstyleTask -> checkstyleTask.doLast {
|
||||
reports.all { report ->
|
||||
def outputFile = report.destination
|
||||
if (outputFile.exists() && outputFile.text.contains("severity=\"error\"")) {
|
||||
throw new GradleException("There were checkstyle errors! For more info check $outputFile")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
preBuild.dependsOn runCheckstyle
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
|
||||
implementation "com.puppycrawl.tools:checkstyle:${checkstyleVersion}"
|
||||
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation "android.arch.persistence.room:testing:1.1.1"
|
||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0', {
|
||||
|
|
@ -164,4 +208,4 @@ static String getGitWorkingBranch() {
|
|||
// git was not found
|
||||
return ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue