From 577b7e431f31d1b93aee65dc75116012ef29daf4 Mon Sep 17 00:00:00 2001 From: Sungyong An Date: Sat, 9 Dec 2023 18:15:20 +0900 Subject: [PATCH] Use Initialization Scripts for spotless --- .editorconfig | 6 ++++++ .github/workflows/build.yaml | 21 +++++++++++++++++---- build.gradle | 15 --------------- gradle/init.gradle.kts | 28 ++++++++++++++++++++++++++++ gradle/libs.versions.toml | 1 - 5 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 .editorconfig create mode 100644 gradle/init.gradle.kts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..a0b4d234b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,6 @@ +# https://editorconfig.org/ +# This configuration is used by ktlint when spotless invokes it + +[*.{kt,kts}] +ij_kotlin_allow_trailing_comma=true +ij_kotlin_allow_trailing_comma_on_call_site=true \ No newline at end of file diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 69c4590fb..cb907f8ad 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -13,10 +13,11 @@ on: jobs: build: runs-on: ubuntu-latest - timeout-minutes: 40 + timeout-minutes: 60 steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 - name: Copy CI gradle.properties run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties @@ -27,5 +28,17 @@ jobs: distribution: temurin java-version: 17 - - name: Build, lint and spotless - run: ./gradlew spotlessCheck dependencyGuard lintDebug assemble --scan + - name: Check dependencyGuard + run: ./gradlew dependencyGuard + + - name: Check spotless + run: ./gradlew spotlessCheck --init-script gradle/init.gradle.kts --stacktrace + + - name: Check lint + run: ./gradlew lintDebug --stacktrace + + - name: Build all build type and flavor permutations + run: ./gradlew assemble --stacktrace + + - name: Run local tests + run: ./gradlew testDebug --stacktrace diff --git a/build.gradle b/build.gradle index 4eb2b5e75..7457e3186 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,6 @@ plugins { alias(libs.plugins.kotlin.jvm) apply false alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.dagger.hilt) apply false - alias(libs.plugins.spotless) apply false alias(libs.plugins.ksp) apply false alias(libs.plugins.dependencyGuard) apply false alias(libs.plugins.firebase.crashlytics) apply false @@ -14,20 +13,6 @@ plugins { apply from: "$rootDir/gradle/version.gradle" -subprojects { - apply plugin: 'com.diffplug.spotless' - spotless { - kotlin { - target '**/*.kt' - targetExclude("$buildDir/**/*.kt") - targetExclude('bin/**/*.kt') - - ktlint("0.41.0") - licenseHeaderFile rootProject.file('spotless/copyright.kt') - } - } -} - Object propOrDef(String propertyName, Object defaultValue) { def properties = new Properties() def keyFile = rootProject.file("signing/key.properties") diff --git a/gradle/init.gradle.kts b/gradle/init.gradle.kts new file mode 100644 index 000000000..c25283f06 --- /dev/null +++ b/gradle/init.gradle.kts @@ -0,0 +1,28 @@ +val ktlintVersion = "0.49.0" + +initscript { + val spotlessVersion = "6.22.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).userData(mapOf("android" to "true")) + licenseHeaderFile(rootProject.file("spotless/copyright.kt")) + } + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 00318d7e5..25e98fc3a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -163,7 +163,6 @@ dagger-hilt = { id = "com.google.dagger.hilt.android", version.ref = "dagger" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } -spotless = { id = "com.diffplug.spotless", version = "6.11.0" } dependencyGuard = { id = "com.dropbox.dependency-guard", version.ref = "dependencyGuard" } firebase-crashlytics = { id = "com.google.firebase.crashlytics", version = "2.9.2" } firebase-perf = { id = "com.google.firebase.firebase-perf", version = "1.4.2" }