Skip to content

Instantly share code, notes, and snippets.

@talenguyen
Created January 20, 2019 23:28
Show Gist options
  • Save talenguyen/0072017e7b987564ba3a05dc72fedf0c to your computer and use it in GitHub Desktop.
Save talenguyen/0072017e7b987564ba3a05dc72fedf0c to your computer and use it in GitHub Desktop.
ktlint configuration
// kotlin-gradle-plugin must be applied for configuration below to work
// (see https://kotlinlang.org/docs/reference/using-gradle.html)
repositories {
jcenter()
}
configurations {
ktlint
}
dependencies {
ktlint "com.github.shyiko:ktlint:0.29.0"
// additional 3rd party ruleset(s) can be specified here
// just add them to the classpath (e.g. ktlint 'groupId:artifactId:version') and
// ktlint will pick them up
}
def outputDir = "${project.buildDir}/reports/ktlint/"
def outputFile = "${outputDir}ktlint-checkstyle-report.xml"
def inputFiles = project.fileTree(dir: "src", include: "**/*.kt")
tasks.register("ktlint", JavaExec) {
inputs.files(inputFiles)
outputs.dir(outputDir)
group = "verification"
description = "Check Kotlin code style."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args = [
"--reporter=plain",
"--reporter=checkstyle,output=${outputFile}",
"**/src/**/*.kt"
]
// to generate report in checkstyle format prepend following args:
// "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml"
// see https://github.com/shyiko/ktlint#usage for more
}
tasks.register("ktlintFormat", JavaExec) {
group = "verification"
description = "Fix Kotlin code style deviations."
classpath = configurations.ktlint
main = "com.github.shyiko.ktlint.Main"
args "-F", "**/src/**/*.kt"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment