Skip to content

Commit

Permalink
configure ktlint in the build-logic module
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Feb 14, 2024
1 parent 292fff9 commit 7486cd2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 17 deletions.
1 change: 1 addition & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(libs.kotlin.gradlePlugin)
implementation(libs.kotlin.kover.gradlePlugin)
implementation(libs.ksp.gradlePlugin)
implementation(libs.ktlint.gradle)
implementation(libs.onesky.gradlePlugin)
}

Expand Down
9 changes: 9 additions & 0 deletions build-logic/src/main/kotlin/KtlintConfiguration.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.gradle.api.Project

fun Project.configureKtlint() {
pluginManager.apply("org.jlleitschuh.gradle.ktlint")

ktlint {
version.set(libs.findVersion("ktlint").get().requiredVersion)
}
}
2 changes: 2 additions & 0 deletions build-logic/src/main/kotlin/Project.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.kotlin.dsl.configure
import org.gradle.kotlin.dsl.getByType
import org.jetbrains.kotlin.gradle.plugin.KaptExtension
import org.jlleitschuh.gradle.ktlint.KtlintExtension

internal fun Project.androidComponents(configure: Action<AndroidComponentsExtension<*, *, *>>): Unit =
extensions.configure("androidComponents", configure)
internal fun Project.kapt(configure: KaptExtension.() -> Unit) = extensions.configure(configure)
internal fun Project.ktlint(action: KtlintExtension.() -> Unit) = extensions.configure(action)

internal val Project.libs get() = project.extensions.getByType<VersionCatalogsExtension>().named("libs")
internal val Project.androidComponents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ android {
}

excludeAndroidSdkDependencies()
configureKtlint()
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ dependencies {
}

excludeAndroidSdkDependencies()
configureKtlint()
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ plugins {
android {
configureAndroidCommon(project)
}

configureKtlint()
17 changes: 0 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType

buildscript {
repositories {
google()
Expand All @@ -20,19 +18,4 @@ buildscript {
plugins {
alias libs.plugins.hilt apply false
alias libs.plugins.ksp apply false
alias libs.plugins.ktlint
}

// configure ktlint
subprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint"

ktlint {
android = true
version = libs.versions.ktlint.get()
reporters {
reporter(ReporterType.PLAIN_GROUP_BY_FILE)
reporter(ReporterType.CHECKSTYLE)
}
}
}

0 comments on commit 7486cd2

Please sign in to comment.