diff --git a/.github/workflows/build-sample.yml b/.github/workflows/build-sample.yml index d4d65a9984..4d0de3cb44 100644 --- a/.github/workflows/build-sample.yml +++ b/.github/workflows/build-sample.yml @@ -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 @@ -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 }} diff --git a/JetLagged/build.gradle.kts b/JetLagged/build.gradle.kts index 0a68895495..2b3f56e8a2 100644 --- a/JetLagged/build.gradle.kts +++ b/JetLagged/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/JetLagged/buildscripts/init.gradle.kts b/JetLagged/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/JetLagged/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/JetLagged/gradle/libs.versions.toml b/JetLagged/gradle/libs.versions.toml index 29300201d3..1cd5b96b62 100644 --- a/JetLagged/gradle/libs.versions.toml +++ b/JetLagged/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/JetNews/build.gradle.kts b/JetNews/build.gradle.kts index 08ccea3e70..30355ffe44 100644 --- a/JetNews/build.gradle.kts +++ b/JetNews/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/JetNews/buildscripts/init.gradle.kts b/JetNews/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/JetNews/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/JetNews/gradle/libs.versions.toml b/JetNews/gradle/libs.versions.toml index 29300201d3..1cd5b96b62 100644 --- a/JetNews/gradle/libs.versions.toml +++ b/JetNews/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/Jetcaster/build.gradle.kts b/Jetcaster/build.gradle.kts index 8488c7159d..bcd5617e23 100644 --- a/Jetcaster/build.gradle.kts +++ b/Jetcaster/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/Jetcaster/buildscripts/init.gradle.kts b/Jetcaster/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/Jetcaster/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/Jetcaster/gradle/libs.versions.toml b/Jetcaster/gradle/libs.versions.toml index b772707772..3cffd54753 100644 --- a/Jetcaster/gradle/libs.versions.toml +++ b/Jetcaster/gradle/libs.versions.toml @@ -54,6 +54,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" @@ -173,4 +174,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" } diff --git a/Jetchat/build.gradle.kts b/Jetchat/build.gradle.kts index 08ccea3e70..30355ffe44 100644 --- a/Jetchat/build.gradle.kts +++ b/Jetchat/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/Jetchat/buildscripts/init.gradle.kts b/Jetchat/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/Jetchat/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/Jetchat/gradle/libs.versions.toml b/Jetchat/gradle/libs.versions.toml index 29300201d3..1cd5b96b62 100644 --- a/Jetchat/gradle/libs.versions.toml +++ b/Jetchat/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/Jetsnack/build.gradle.kts b/Jetsnack/build.gradle.kts index 08ccea3e70..30355ffe44 100644 --- a/Jetsnack/build.gradle.kts +++ b/Jetsnack/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/Jetsnack/buildscripts/init.gradle.kts b/Jetsnack/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/Jetsnack/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/Jetsnack/gradle/libs.versions.toml b/Jetsnack/gradle/libs.versions.toml index 29300201d3..1cd5b96b62 100644 --- a/Jetsnack/gradle/libs.versions.toml +++ b/Jetsnack/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/Reply/build.gradle.kts b/Reply/build.gradle.kts index 0a68895495..2b3f56e8a2 100644 --- a/Reply/build.gradle.kts +++ b/Reply/build.gradle.kts @@ -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") + configure { + 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() + } + } +} diff --git a/Reply/buildscripts/init.gradle.kts b/Reply/buildscripts/init.gradle.kts deleted file mode 100644 index 1b7a54264c..0000000000 --- a/Reply/buildscripts/init.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -val ktlintVersion = "0.46.1" - -initscript { - val spotlessVersion = "6.10.0" - - repositories { - mavenCentral() - } - - dependencies { - classpath("com.diffplug.spotless:spotless-plugin-gradle:$spotlessVersion") - } -} - -allprojects { - if (this == rootProject) { - return@allprojects - } - apply() - extensions.configure { - kotlin { - target("**/*.kt") - targetExclude("**/build/**/*.kt") - ktlint(ktlintVersion).editorConfigOverride( - mapOf( - "ktlint_code_style" to "android", - "ij_kotlin_allow_trailing_comma" to true, - // 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"), "(^(?![\\/ ]\\*).*$)") - } - } -} \ No newline at end of file diff --git a/Reply/gradle/libs.versions.toml b/Reply/gradle/libs.versions.toml index 29300201d3..1cd5b96b62 100644 --- a/Reply/gradle/libs.versions.toml +++ b/Reply/gradle/libs.versions.toml @@ -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" @@ -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" }