From c31e75f02f3021c52f6c24f655e2bded0c8b2b33 Mon Sep 17 00:00:00 2001 From: Andreas Date: Thu, 19 Jan 2023 04:33:56 +0100 Subject: [PATCH] Create plugin for linting (#8942) --- .github/workflows/build_pull_request.yml | 2 +- .github/workflows/build_push.yml | 2 +- app/build.gradle.kts | 6 +----- build.gradle.kts | 20 +------------------ buildSrc/build.gradle.kts | 6 ++++-- buildSrc/settings.gradle.kts | 6 ++++++ .../src/main/kotlin/tachiyomi.lint.gradle.kts | 20 +++++++++++++++++++ core/build.gradle.kts | 1 + gradle/androidx.versions.toml | 7 ++----- gradle/kotlinx.versions.toml | 4 ++-- gradle/libs.versions.toml | 5 ++--- i18n/build.gradle.kts | 1 + macrobenchmark/build.gradle.kts | 1 + source-api/build.gradle.kts | 1 + .../eu/kanade/tachiyomi/source/model/Page.kt | 1 + 15 files changed, 45 insertions(+), 38 deletions(-) create mode 100644 buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts diff --git a/.github/workflows/build_pull_request.yml b/.github/workflows/build_pull_request.yml index 051c2e46db..9b6ede0c31 100644 --- a/.github/workflows/build_pull_request.yml +++ b/.github/workflows/build_pull_request.yml @@ -36,4 +36,4 @@ jobs: - name: Build app and run unit tests uses: gradle/gradle-command-action@v2 with: - arguments: assembleStandardRelease testStandardReleaseUnitTest \ No newline at end of file + arguments: lintKotlin assembleStandardRelease testStandardReleaseUnitTest \ No newline at end of file diff --git a/.github/workflows/build_push.yml b/.github/workflows/build_push.yml index 588d199a04..5bea25988b 100644 --- a/.github/workflows/build_push.yml +++ b/.github/workflows/build_push.yml @@ -31,7 +31,7 @@ jobs: - name: Build app and run unit tests uses: gradle/gradle-command-action@v2 with: - arguments: assembleStandardRelease testStandardReleaseUnitTest + arguments: lintKotlin assembleStandardRelease testStandardReleaseUnitTest # Sign APK and create release for tags diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 2ed374a7a9..7e6126557e 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("com.android.application") id("com.mikepenz.aboutlibraries.plugin") kotlin("android") + id("tachiyomi.lint") kotlin("plugin.serialization") id("com.github.zellius.shortcut-helper") id("com.squareup.sqldelight") @@ -346,11 +347,6 @@ tasks { ) } } - - preBuild { - val ktlintTask = if (System.getenv("GITHUB_BASE_REF") == null) formatKotlin else lintKotlin - dependsOn(ktlintTask) - } } buildscript { diff --git a/build.gradle.kts b/build.gradle.kts index 8d8911245f..10b653f9cd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,30 +3,12 @@ buildscript { classpath(libs.android.shortcut.gradle) classpath(libs.google.services.gradle) classpath(libs.aboutLibraries.gradle) - classpath(kotlinx.serialization.gradle) classpath(libs.sqldelight.gradle) } } plugins { - alias(androidx.plugins.application) apply false - alias(androidx.plugins.library) apply false - alias(androidx.plugins.test) apply false - alias(kotlinx.plugins.android) apply false - alias(libs.plugins.kotlinter) -} - -subprojects { - apply() - - kotlinter { - experimentalRules = true - - disabledRules = arrayOf( - "experimental:argument-list-wrapping", // Doesn't play well with Android Studio - "filename", // Often broken to give a more general name - ) - } + alias(kotlinx.plugins.serialization) apply false } tasks.register("clean") { diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index c2d9536892..b5854fcb55 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -3,12 +3,14 @@ plugins { } dependencies { - compileOnly("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinLibs.versions.kotlin.version.get()}") - + implementation(androidxLibs.gradle) + implementation(kotlinLibs.gradle) + implementation(libs.kotlinter) implementation(gradleApi()) } repositories { + gradlePluginPortal() mavenCentral() google() } diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts index 807fe41ca0..05a279df09 100644 --- a/buildSrc/settings.gradle.kts +++ b/buildSrc/settings.gradle.kts @@ -1,5 +1,11 @@ dependencyResolutionManagement { versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + create("androidxLibs") { + from(files("../gradle/androidx.versions.toml")) + } create("kotlinLibs") { from(files("../gradle/kotlinx.versions.toml")) } diff --git a/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts b/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts new file mode 100644 index 0000000000..12b7b2295b --- /dev/null +++ b/buildSrc/src/main/kotlin/tachiyomi.lint.gradle.kts @@ -0,0 +1,20 @@ +import org.jmailen.gradle.kotlinter.KotlinterExtension +import org.jmailen.gradle.kotlinter.KotlinterPlugin + +apply() + +extensions.configure("kotlinter") { + experimentalRules = true + + disabledRules = arrayOf( + "experimental:argument-list-wrapping", // Doesn't play well with Android Studio + "filename", // Often broken to give a more general name + ) +} + +tasks { + named("preBuild").configure { + if (!System.getenv("CI").toBoolean()) + dependsOn("formatKotlin") + } +} diff --git a/core/build.gradle.kts b/core/build.gradle.kts index f769da7c3c..0334387a5e 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.library") kotlin("android") + id("tachiyomi.lint") kotlin("plugin.serialization") } diff --git a/gradle/androidx.versions.toml b/gradle/androidx.versions.toml index ec9184415e..96c491b563 100644 --- a/gradle/androidx.versions.toml +++ b/gradle/androidx.versions.toml @@ -3,6 +3,8 @@ agp_version = "7.4.0" lifecycle_version = "2.5.1" [libraries] +gradle = { module = "com.android.tools.build:gradle", version.ref = "agp_version" } + annotation = "androidx.annotation:annotation:1.5.0" appcompat = "androidx.appcompat:appcompat:1.6.0" biometricktx = "androidx.biometric:biometric-ktx:1.2.0-alpha05" @@ -33,8 +35,3 @@ test-uiautomator = "androidx.test.uiautomator:uiautomator:2.2.0" [bundles] lifecycle = ["lifecycle-common", "lifecycle-process", "lifecycle-runtimektx"] workmanager = ["work-runtime", "guava"] - -[plugins] -application = { id = "com.android.application", version.ref = "agp_version" } -library = { id = "com.android.library", version.ref = "agp_version" } -test = { id = "com.android.test", version.ref = "agp_version" } diff --git a/gradle/kotlinx.versions.toml b/gradle/kotlinx.versions.toml index 6f944b83cf..bc62e6408e 100644 --- a/gradle/kotlinx.versions.toml +++ b/gradle/kotlinx.versions.toml @@ -15,7 +15,6 @@ coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-androi serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version = "1.4.0" } serialization-json-okio = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-okio", version = "1.4.0" } serialization-protobuf = { module = "org.jetbrains.kotlinx:kotlinx-serialization-protobuf", version.ref = "serialization_version" } -serialization-gradle = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "kotlin_version" } serialization-xml-core = { module = "io.github.pdvrieze.xmlutil:core-android", version.ref = "xml_serialization_version" } serialization-xml = { module = "io.github.pdvrieze.xmlutil:serialization-android", version.ref = "xml_serialization_version" } @@ -24,4 +23,5 @@ coroutines = ["coroutines-core", "coroutines-android"] serialization = ["serialization-json", "serialization-json-okio", "serialization-protobuf", "serialization-xml-core", "serialization-xml"] [plugins] -android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin_version" } \ No newline at end of file +android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin_version" } +serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin_version" } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d30e9c67e7..87540e5d47 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -89,6 +89,8 @@ voyager-navigator = { module = "ca.gosyer:voyager-navigator", version.ref = "voy voyager-tab-navigator = { module = "ca.gosyer:voyager-tab-navigator", version.ref = "voyager" } voyager-transitions = { module = "ca.gosyer:voyager-transitions", version.ref = "voyager" } +kotlinter = "org.jmailen.gradle:kotlinter-gradle:3.13.0" + [bundles] reactivex = ["rxandroid", "rxjava", "rxrelay"] okhttp = ["okhttp-core", "okhttp-logging", "okhttp-dnsoverhttps"] @@ -98,6 +100,3 @@ coil = ["coil-core", "coil-gif", "coil-compose"] shizuku = ["shizuku-api", "shizuku-provider"] voyager = ["voyager-navigator", "voyager-tab-navigator", "voyager-transitions"] richtext = ["richtext-commonmark", "richtext-m3"] - -[plugins] -kotlinter = { id = "org.jmailen.kotlinter", version = "3.13.0" } \ No newline at end of file diff --git a/i18n/build.gradle.kts b/i18n/build.gradle.kts index 42239ed07c..e0d5f475df 100644 --- a/i18n/build.gradle.kts +++ b/i18n/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.library") kotlin("android") + id("tachiyomi.lint") } android { diff --git a/macrobenchmark/build.gradle.kts b/macrobenchmark/build.gradle.kts index 60ef1043f7..0b32ad0475 100644 --- a/macrobenchmark/build.gradle.kts +++ b/macrobenchmark/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.test") kotlin("android") + id("tachiyomi.lint") } android { diff --git a/source-api/build.gradle.kts b/source-api/build.gradle.kts index 89b281543f..b530eba004 100644 --- a/source-api/build.gradle.kts +++ b/source-api/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.android.library") kotlin("android") + id("tachiyomi.lint") kotlin("plugin.serialization") } diff --git a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt b/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt index 44180c6a32..a43918f558 100644 --- a/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt +++ b/source-api/src/main/java/eu/kanade/tachiyomi/source/model/Page.kt @@ -29,6 +29,7 @@ open class Page( @Transient private val _progressFlow = MutableStateFlow(0) + @Transient val progressFlow = _progressFlow.asStateFlow() var progress: Int