From f5f8e5d279a2036afeb083e44768378d0a8752c8 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Fri, 1 May 2020 20:09:52 +0200 Subject: [PATCH] Add Ktlint --- app/build.gradle | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index b99e89271..5a0c00bba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -116,25 +116,40 @@ task runCheckstyle(type: Checkstyle) { } } -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") - } +runCheckstyle.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") } } } +configurations { + ktlint +} + +task runKtlint(type: JavaExec) { + main = "com.pinterest.ktlint.Main" + classpath = configurations.ktlint + args "src/**/*.kt" +} + +task formatKtlint(type: JavaExec) { + main = "com.pinterest.ktlint.Main" + classpath = configurations.ktlint + args "-F", "src/**/*.kt" +} + afterEvaluate { - preDebugBuild.dependsOn runCheckstyle + preDebugBuild.dependsOn runCheckstyle, runKtlint } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" debugImplementation "com.puppycrawl.tools:checkstyle:${checkstyleVersion}" + ktlint "com.pinterest:ktlint:0.35.0" androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation "android.arch.persistence.room:testing:1.1.1"