在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):jeremymailen/kotlinter-gradle开源软件地址(OpenSource Url):https://github.com/jeremymailen/kotlinter-gradle开源编程语言(OpenSource Language):Kotlin 100.0%开源软件介绍(OpenSource Introduction):Kotlinter GradlePainless Gradle plugin for linting and formatting Kotlin source files using the awesome ktlint engine. It aims to be easy to set up with zero required configuration and behaves as you'd expect out of the box. It's also fast because it integrates the ktlint engine directly with Gradle's incremental build and uses the Worker API to parallelize work. InstallationAvailable on the Gradle Plugins Portal: https://plugins.gradle.org/plugin/org.jmailen.kotlinter Single moduleKotlinplugins {
id("org.jmailen.kotlinter") version "3.11.1"
} Groovyplugins {
id "org.jmailen.kotlinter" version "3.11.1"
} Multi-module and AndroidKotlinRoot `build.gradle.kts`plugins {
id("org.jmailen.kotlinter") version "3.11.1" apply false
} Each module plugins {
id("org.jmailen.kotlinter")
} GroovyRoot `build.gradle`plugins {
id 'org.jmailen.kotlinter' version "3.11.1" apply false
} Each module plugins {
id 'org.jmailen.kotlinter'
} Compatibility
Features
TasksWhen your project uses one of the supported Kotlin Gradle plugins, Kotlinter adds these tasks:
Also Granular tasks are added for each source set in the project: Git HooksKotlinter can install a hook to run pre-push ( You must apply the kotlinter plugin to your root project to make this task available. If using To install the hook automatically when someone runs the build, add this to your root project Kotlintasks.check {
dependsOn("installKotlinterPrePushHook")
} Groovytasks.named('check') {
dependsOn 'installKotlinterPrePushHook'
} ConfigurationOptions are configured in the Kotlinkotlinter {
ignoreFailures = false
reporters = arrayOf("checkstyle", "plain")
experimentalRules = false
disabledRules = emptyArray()
} Groovykotlinter {
ignoreFailures = false
reporters = ['checkstyle', 'plain']
experimentalRules = false
disabledRules = []
} Options for Reporters behave as described at: https://github.com/pinterest/ktlint The The disabledRules = ["no-wildcard-imports"] You must prefix rule ids not part of the standard rule set with EditorconfigKotlinter will configure itself using an If a non-empty See Ktlint editorconfig for supported values. Customizing TasksThe Kotlintasks.lintKotlinMain {
exclude("com/example/**/generated/*.kt")
} Groovytasks.named('lintKotlinMain') {
exclude 'com/example/**/generated/*.kt'
} Note that exclude paths are relative to the package root. Custom TasksIf you aren't using autoconfiguration from a supported plugin or otherwise need to handle additional source code, you can create custom tasks: Kotlinimport org.jmailen.gradle.kotlinter.tasks.LintTask
import org.jmailen.gradle.kotlinter.tasks.FormatTask
tasks.register<LintTask>("ktLint") {
group = "verification"
source(files("src"))
reports.set(
mapOf(
"plain" to file("build/lint-report.txt"),
"json" to file("build/lint-report.json")
)
)
}
tasks.register<FormatTask>("ktFormat") {
group = "formatting"
source(files("src"))
report.set(file("build/format-report.txt"))
} Groovyimport org.jmailen.gradle.kotlinter.tasks.LintTask
import org.jmailen.gradle.kotlinter.tasks.FormatTask
tasks.register('ktLint', LintTask) {
group 'verification'
source files('src')
reports = [
'plain': file('build/lint-report.txt'),
'json' : file('build/lint-report.json')
]
disabledRules = ['import-ordering']
}
tasks.register('ktFormat', FormatTask) {
group 'formatting'
source files('src/test')
report = file('build/format-report.txt')
disabledRules = ['import-ordering']
} Custom ktlint versionIf you need to use a different version of Kotlinbuildscript {
configurations.classpath {
resolutionStrategy {
force(
"com.pinterest.ktlint:ktlint-core:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-checkstyle:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-json:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-html:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-plain:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-sarif:0.39.0",
"com.pinterest.ktlint:ktlint-ruleset-experimental:0.39.0",
"com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0"
)
}
}
} Groovybuildscript {
configurations.classpath {
resolutionStrategy {
force(
"com.pinterest.ktlint:ktlint-core:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-checkstyle:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-json:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-html:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-plain:0.39.0",
"com.pinterest.ktlint:ktlint-reporter-sarif:0.39.0",
"com.pinterest.ktlint:ktlint-ruleset-experimental:0.39.0",
"com.pinterest.ktlint:ktlint-ruleset-standard:0.39.0"
)
}
}
} Custom RulesYou can add custom ktlint RuleSets using the Kotlinbuildscript {
dependencies {
classpath(files("libs/my-custom-ktlint-rules.jar"))
classpath("org.other.ktlint:custom-rules:1.0")
}
} Groovybuildscript {
dependencies {
classpath files('libs/my-custom-ktlint-rules.jar')
classpath 'org.other.ktlint:custom-rules:1.0'
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论