Skip to content

Move Spotless configurations from buildscripts/init.gradle.kts to build.gradle.kts #1549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 15, 2025
Merged
6 changes: 5 additions & 1 deletion .github/workflows/build-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
with:
# https://github.com/diffplug/spotless/issues/710
# Check out full history for Spotless to ensure ratchetFrom can find the ratchet version
fetch-depth: 0

- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties
Expand All @@ -59,7 +63,7 @@ jobs:

- name: Check formatting
working-directory: ${{ inputs.path }}
run: ./gradlew --init-script buildscripts/init.gradle.kts spotlessCheck --stacktrace
run: ./gradlew spotlessCheck --stacktrace

- name: Check lint
working-directory: ${{ inputs.path }}
Expand Down
47 changes: 47 additions & 0 deletions JetLagged/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,53 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.spotless) apply false
}

apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

subprojects {
apply(plugin = "com.diffplug.spotless")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The plugin is already applied at the top level, so this apply call is redundant and can be removed to simplify the configuration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is correct because I want to apply the plugin to the subprojects. @bentrengrove do you see any optimization I can make?

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
ratchetFrom = "origin/main"
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint().editorConfigOverride(
mapOf(
"ktlint_code_style" to "android_studio",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The ktlint_code_style is set to android_studio here. In the original configuration in buildscripts/init.gradle.kts (line 42), it was set to android. Is this change intentional? If so, please add a comment explaining why.

"ij_kotlin_allow_trailing_comma" to true,
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
// These rules were introduced in ktlint 0.46.0 and should not be
// enabled without further discussion. They are disabled for now.
// See: https://github.com/pinterest/ktlint/releases/tag/0.46.0
"disabled_rules" to
"filename," +
"annotation,annotation-spacing," +
"argument-list-wrapping," +
"double-colon-spacing," +
"enum-entry-name-case," +
"multiline-if-else," +
"no-empty-first-line-in-method-block," +
"package-name," +
"trailing-comma," +
"spacing-around-angle-brackets," +
"spacing-between-declarations-with-annotations," +
"spacing-between-declarations-with-comments," +
"unary-op-spacing"
)
)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)")
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
}
}
72 changes: 0 additions & 72 deletions JetLagged/buildscripts/init.gradle.kts

This file was deleted.

2 changes: 2 additions & 0 deletions JetLagged/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ roborazzi = "1.42.0"
rome = "2.1.0"
room = "2.6.1"
secrets = "2.0.1"
spotless = "7.0.3"
# @keep
targetSdk = "33"
version-catalog-update = "0.8.5"
Expand Down Expand Up @@ -171,4 +172,5 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
47 changes: 47 additions & 0 deletions JetNews/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,53 @@ plugins {
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.spotless) apply false
}

apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

subprojects {
apply(plugin = "com.diffplug.spotless")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The plugin is already applied at the top level, so this apply call is redundant and can be removed to simplify the configuration.

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
ratchetFrom = "origin/main"
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint().editorConfigOverride(
mapOf(
"ktlint_code_style" to "android_studio",
"ij_kotlin_allow_trailing_comma" to true,
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
// These rules were introduced in ktlint 0.46.0 and should not be
// enabled without further discussion. They are disabled for now.
// See: https://github.com/pinterest/ktlint/releases/tag/0.46.0
"disabled_rules" to
"filename," +
"annotation,annotation-spacing," +
"argument-list-wrapping," +
"double-colon-spacing," +
"enum-entry-name-case," +
"multiline-if-else," +
"no-empty-first-line-in-method-block," +
"package-name," +
"trailing-comma," +
"spacing-around-angle-brackets," +
"spacing-between-declarations-with-annotations," +
"spacing-between-declarations-with-comments," +
"unary-op-spacing"
)
)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)")
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
}
}
72 changes: 0 additions & 72 deletions JetNews/buildscripts/init.gradle.kts

This file was deleted.

2 changes: 2 additions & 0 deletions JetNews/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ roborazzi = "1.42.0"
rome = "2.1.0"
room = "2.6.1"
secrets = "2.0.1"
spotless = "7.0.3"
# @keep
targetSdk = "33"
version-catalog-update = "0.8.5"
Expand Down Expand Up @@ -171,4 +172,5 @@ kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", versi
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
roborazzi = { id = "io.github.takahirom.roborazzi", version.ref = "roborazzi" }
secrets = { id = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", version.ref = "secrets" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
version-catalog-update = { id = "nl.littlerobots.version-catalog-update", version.ref = "version-catalog-update" }
47 changes: 47 additions & 0 deletions Jetcaster/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,53 @@ plugins {
alias(libs.plugins.hilt) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.compose) apply false
alias(libs.plugins.spotless) apply false
}

apply("${project.rootDir}/buildscripts/toml-updater-config.gradle")

subprojects {
apply(plugin = "com.diffplug.spotless")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The plugin is already applied at the top level, so this apply call is redundant and can be removed to simplify the configuration.

configure<com.diffplug.gradle.spotless.SpotlessExtension> {
ratchetFrom = "origin/main"
kotlin {
target("**/*.kt")
targetExclude("**/build/**/*.kt")
ktlint().editorConfigOverride(
mapOf(
"ktlint_code_style" to "android_studio",
"ij_kotlin_allow_trailing_comma" to true,
"ktlint_function_naming_ignore_when_annotated_with" to "Composable",
// These rules were introduced in ktlint 0.46.0 and should not be
// enabled without further discussion. They are disabled for now.
// See: https://github.com/pinterest/ktlint/releases/tag/0.46.0
"disabled_rules" to
"filename," +
"annotation,annotation-spacing," +
"argument-list-wrapping," +
"double-colon-spacing," +
"enum-entry-name-case," +
"multiline-if-else," +
"no-empty-first-line-in-method-block," +
"package-name," +
"trailing-comma," +
"spacing-around-angle-brackets," +
"spacing-between-declarations-with-annotations," +
"spacing-between-declarations-with-comments," +
"unary-op-spacing"
)
)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"))
}
format("kts") {
target("**/*.kts")
targetExclude("**/build/**/*.kts")
// Look for the first line that doesn't have a block comment (assumed to be the license)
licenseHeaderFile(rootProject.file("spotless/copyright.kt"), "(^(?![\\/ ]\\*).*$)")
}
kotlinGradle {
target("*.gradle.kts")
ktlint()
}
}
}
Loading