From dc5f07b03eb47a1b0a32692234ee1f154bd6e424 Mon Sep 17 00:00:00 2001 From: Julian Kalinowski Date: Wed, 30 Aug 2023 16:45:03 +0200 Subject: [PATCH] chore: use spotless --- .../workflows/{ktlint.yml => spotless.yml} | 8 +-- _ktlint.gradle | 25 ---------- build.gradle | 30 +++++++---- gradle/libs.versions.toml | 11 ++-- revealswipe/build.gradle | 3 +- sample/build.gradle | 3 +- settings.gradle | 9 ++++ spotless/greclipse.properties | 50 +++++++++++++++++++ 8 files changed, 94 insertions(+), 45 deletions(-) rename .github/workflows/{ktlint.yml => spotless.yml} (89%) delete mode 100644 _ktlint.gradle create mode 100644 spotless/greclipse.properties diff --git a/.github/workflows/ktlint.yml b/.github/workflows/spotless.yml similarity index 89% rename from .github/workflows/ktlint.yml rename to .github/workflows/spotless.yml index 0cc3649..fbcb124 100644 --- a/.github/workflows/ktlint.yml +++ b/.github/workflows/spotless.yml @@ -1,4 +1,4 @@ -name: Ktlint +name: Spotless on: pull_request: @@ -10,8 +10,8 @@ on: - main jobs: - ktlint: - if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]') && ! (contains(toJSON(github.event.commits.*.message), '[skip ') && contains(toJSON(github.event.commits.*.message), '#ktlint'))" + spotless: + if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]') && ! (contains(toJSON(github.event.commits.*.message), '[skip ') && contains(toJSON(github.event.commits.*.message), '#spotless'))" runs-on: ubuntu-latest steps: @@ -26,4 +26,4 @@ jobs: run: chmod +x gradlew - name: Build with Gradle - run: ./gradlew ktlint \ No newline at end of file + run: ./gradlew spotlessCheck \ No newline at end of file diff --git a/_ktlint.gradle b/_ktlint.gradle deleted file mode 100644 index cf8854f..0000000 --- a/_ktlint.gradle +++ /dev/null @@ -1,25 +0,0 @@ -configurations { - ktlint -} - -dependencies { - ktlint "com.pinterest:ktlint:0.41.0" -} - -task ktlint(type: JavaExec, group: "verification") { - description = "Check Kotlin code style." - main = "com.pinterest.ktlint.Main" - classpath = configurations.ktlint - args "**/*.kt" - // to generate report in checkstyle format prepend following args: - // "--reporter=plain", "--reporter=checkstyle,output=${buildDir}/ktlint.xml" - // see https://github.com/pinterest/ktlint#usage for more -} -check.dependsOn ktlint - -task ktlintFormat(type: JavaExec, group: "formatting") { - description = "Fix Kotlin code style deviations." - main = "com.pinterest.ktlint.Main" - classpath = configurations.ktlint - args "-F", "src/**/*.kt" -} diff --git a/build.gradle b/build.gradle index f7e516b..160e022 100644 --- a/build.gradle +++ b/build.gradle @@ -1,21 +1,31 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - - repositories { - google() - mavenCentral() - } dependencies { classpath libs.kotlin.pluginGradle classpath libs.gradle - classpath libs.gradle.nexus.staging.plugin - - // NOTE: Do not place your application dependencies here; they belong - // in the individual module build.gradle files } } -apply plugin: 'io.codearte.nexus-staging' +plugins { + alias libs.plugins.spotless apply false + alias libs.plugins.nexus.staging apply true +} + +subprojects { + project.afterEvaluate { + spotless { + kotlin { + target "/.kt" + ktlint(libs.versions.ktlint.get()) + } + + groovyGradle { + target '/.gradle' + greclipse().configFile(rootProject.file('spotless/greclipse.properties')) + } + } + } +} tasks.register('clean', Delete) { delete rootProject.layout.buildDir diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 7414f02..33a2bc9 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,7 +3,7 @@ compileSdk = "33" gradleNexusStagingPlugin = "0.30.0" minSdk = "21" targetSdk = "33" -buildToolsVersion = "33.0.1" +ktlint = "0.42.1" composeBom = "2023.04.00" composeCompiler = '1.4.5' @@ -13,6 +13,8 @@ kotlin = "1.8.20" activityComposeVersion = "1.3.1" lifecycleRuntimeKtxVersion = "2.3.1" +spotless = "6.21.0" + [libraries] compose-bom = { module = "androidx.compose:compose-bom", version.ref = "composeBom" } compose-foundation-foundation = { module = "androidx.compose.foundation:foundation" } @@ -21,8 +23,11 @@ compose-ui-tooling = { module = "androidx.compose.ui:ui-tooling" } compose-ui-ui = { module = "androidx.compose.ui:ui" } compose-ui-util = { module = "androidx.compose.ui:ui-util" } gradle = { module = "com.android.tools.build:gradle", version.ref = "gradle" } -gradle-nexus-staging-plugin = { module = "io.codearte.gradle.nexus:gradle-nexus-staging-plugin", version.ref = "gradleNexusStagingPlugin" } kotlin-pluginGradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" } activity-compose = { module = "androidx.activity:activity-compose", version.ref = "activityComposeVersion" } -lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtxVersion" } \ No newline at end of file +lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtxVersion" } + +[plugins] +spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } +nexus-staging = { id = 'io.codearte.nexus-staging', version.ref = "gradleNexusStagingPlugin" } \ No newline at end of file diff --git a/revealswipe/build.gradle b/revealswipe/build.gradle index 327bb78..428a658 100644 --- a/revealswipe/build.gradle +++ b/revealswipe/build.gradle @@ -1,9 +1,9 @@ plugins { id 'com.android.library' id 'kotlin-android' + alias libs.plugins.spotless } -apply from: '../_ktlint.gradle' apply from: '../buildCompose.gradle' ext { @@ -17,7 +17,6 @@ apply from: '../_publish.gradle' android { namespace = "de.charlex.compose.revealswipe" compileSdk libs.versions.compileSdk.get().toInteger() - buildToolsVersion libs.versions.buildToolsVersion.get() defaultConfig { minSdk libs.versions.minSdk.get().toInteger() diff --git a/sample/build.gradle b/sample/build.gradle index b201f6d..c15dc4c 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -1,11 +1,12 @@ plugins { id 'com.android.application' id 'org.jetbrains.kotlin.android' + alias libs.plugins.spotless } + android { namespace = "de.charlex.compose.revealswipe.sample" compileSdk libs.versions.compileSdk.get().toInteger() - buildToolsVersion libs.versions.buildToolsVersion.get() defaultConfig { minSdk libs.versions.minSdk.get().toInteger() diff --git a/settings.gradle b/settings.gradle index 01b29ef..b4a08b6 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,11 @@ +pluginManagement { + repositories { + google() + mavenCentral() + gradlePluginPortal() + } +} + dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { @@ -5,6 +13,7 @@ dependencyResolutionManagement { mavenCentral() } } + rootProject.name = "RevealSwipe" include ':revealswipe' include ':sample' diff --git a/spotless/greclipse.properties b/spotless/greclipse.properties new file mode 100644 index 0000000..ba61c31 --- /dev/null +++ b/spotless/greclipse.properties @@ -0,0 +1,50 @@ +# +# Copyright 2020 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. +# + +#Whether to use 'space', 'tab' or 'mixed' (both) characters for indentation. +#The default value is 'tab'. +org.eclipse.jdt.core.formatter.tabulation.char=space + +#Number of spaces used for indentation in case 'space' characters +#have been selected. The default value is 4. +org.eclipse.jdt.core.formatter.tabulation.size=4 + +#Number of spaces used for indentation in case 'mixed' characters +#have been selected. The default value is 4. +org.eclipse.jdt.core.formatter.indentation.size=4 + +#Whether or not indentation characters are inserted into empty lines. +#The default value is 'true'. +org.eclipse.jdt.core.formatter.indent_empty_lines=false + +#Number of spaces used for multiline indentation. +#The default value is 2. +groovy.formatter.multiline.indentation=2 + +#Length after which list are considered too long. These will be wrapped. +#The default value is 30. +groovy.formatter.longListLength=30 + +#Whether opening braces position shall be the next line. +#The default value is 'same'. +groovy.formatter.braces.start=same + +#Whether closing braces position shall be the next line. +#The default value is 'next'. +groovy.formatter.braces.end=next + +#Remove unnecessary semicolons. The default value is 'false'. +groovy.formatter.remove.unnecessary.semicolons=false \ No newline at end of file