
프로젝트 build.gradle.kts
plugins {
alias(libs.plugins.spotless)
// or
id("com.diffplug.spotless").version("6.19.0")
}
subprojects {
// 모든 모듈 적용할 때 사용합니다.
// 특정 모듈에만 적용하려면 모듈 build.gradle.kts에 직접 적용하면됩니다.
plugins.apply(rootProject.libs.plugins.spotless.get().pluginId)
// or
plugins.apply("com.diffplug.spotless")
configure<SpotlessExtension> {
kotlin {
target("**/*.kt")
ktlint()
indentWithSpaces()
endWithNewline()
}
kotlinGradle {
target("**/*.gradle.kts")
ktlint()
indentWithSpaces()
endWithNewline()
}
java {
target("**/*.java")
indentWithSpaces()
endWithNewline()
removeUnusedImports()
}
}
}
indentWithSpaces, endWithNewline spotless 옵션을 줄 수 있습니다.ktlint, diktat 등 외부 플러그인을 쉽게 사용할 수 있습니다.ktlint("0.50.0") 같은 방식으로 특정 버전을 설정할 수 있습니다../gradlew spotlessCheck : spotless 컨벤션 검사./gradlew spotlessApply : spotless 컨벤션 적용, 적용할 수 없는 케이스는 에러가 발생합니다.subprojects {
/*
*/
afterEvaluate {
runCatching {
tasks.getByPath("classes").dependsOn(tasks.spotlessApply)
}
runCatching {
tasks.getByPath("preBuild").dependsOn(tasks.spotlessApply)
}
}
}