From 9eecc45114dd9632b32d1674f9924e84d535f353 Mon Sep 17 00:00:00 2001 From: Lasta apps Date: Wed, 3 Jul 2024 02:04:16 +0300 Subject: [PATCH] build: Kotlin 2.0, compose, convention plugins rewrite --- .gitignore | 1 + api/agata/build.gradle.kts | 12 +-- app/build.gradle.kts | 3 +- .../ui/components/placeholders/Placeholder.kt | 1 + build.gradle.kts | 3 +- gradle.properties | 3 +- gradle/libs.versions.toml | 14 ++-- gradle/plugins/convention/build.gradle.kts | 17 ++--- .../extensions/DependencyExtensions.kt | 6 -- .../lastaapps/extensions/PojectExtensions.kt | 56 ++++++++++++-- .../android/AndroidAppComposeConvention.kt | 37 ---------- .../plugin/android/AndroidAppConvention.kt | 6 +- .../plugin/android/AndroidKspConvention.kt | 3 +- .../AndroidLibraryComposeConvention.kt | 37 ---------- .../android/AndroidLibraryConvention.kt | 4 +- .../android/common/CoroutinesConvention.kt | 13 ++-- .../android/common/KotlinBaseConvention.kt | 29 +++++--- .../plugin/android/config/ComposeConfig.kt | 73 ------------------- .../android/config/KoltinAndroidConfig.kt | 18 ++--- .../plugin/common/ComposeConvention.kt | 70 ++++++++++++++++++ .../lastaapps/plugin/jvm/JvmAppConvention.kt | 9 +-- .../multiplatform/KMPLibraryConvention.kt | 52 ++----------- lastaapps/common/build.gradle.kts | 5 +- lastaapps/crash/build.gradle.kts | 5 +- 24 files changed, 199 insertions(+), 278 deletions(-) delete mode 100644 gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppComposeConvention.kt delete mode 100644 gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryComposeConvention.kt delete mode 100644 gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/ComposeConfig.kt create mode 100644 gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/common/ComposeConvention.kt diff --git a/.gitignore b/.gitignore index 23adaef3..cf2ced65 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ local.properties /gradle/libs.versions.updates.toml /.idea/other.xml +.kotlin diff --git a/api/agata/build.gradle.kts b/api/agata/build.gradle.kts index 89b2db8e..59a85d28 100644 --- a/api/agata/build.gradle.kts +++ b/api/agata/build.gradle.kts @@ -34,12 +34,12 @@ dependencies { // androidMainImplementation(projects.htmlParser) androidMainImplementation("it.skrape:skrapeit:1.2.2") // fix security vulnerabilities in skrapeit libs - implementation("ch.qos.logback:logback-core:1.4.12") - implementation("ch.qos.logback:logback-classic:1.4.12") - implementation("commons-net:commons-net:3.9.0") - implementation("org.apache.commons:commons-text:1.10.0") - implementation("org.jsoup:jsoup:1.15.3") - implementation("xalan:xalan:2.7.3") + androidMainImplementation("ch.qos.logback:logback-core:1.4.12") + androidMainImplementation("ch.qos.logback:logback-classic:1.4.12") + androidMainImplementation("commons-net:commons-net:3.9.0") + androidMainImplementation("org.apache.commons:commons-text:1.10.0") + androidMainImplementation("org.jsoup:jsoup:1.15.3") + androidMainImplementation("xalan:xalan:2.7.3") commonMainImplementation(libs.ktor.client.core) commonMainImplementation(libs.ktor.client.contentNegotiation) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 5c21a35d..1e9e8160 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -18,8 +18,9 @@ */ plugins { - alias(libs.plugins.lastaapps.android.app.compose) + alias(libs.plugins.lastaapps.android.app) alias(libs.plugins.lastaapps.common.coil) + alias(libs.plugins.lastaapps.common.compose) alias(libs.plugins.aboutLibraries) alias(libs.plugins.kotlin.atomicfu) } diff --git a/app/src/main/kotlin/cz/lastaapps/menza/ui/components/placeholders/Placeholder.kt b/app/src/main/kotlin/cz/lastaapps/menza/ui/components/placeholders/Placeholder.kt index d6dc9907..09130f01 100644 --- a/app/src/main/kotlin/cz/lastaapps/menza/ui/components/placeholders/Placeholder.kt +++ b/app/src/main/kotlin/cz/lastaapps/menza/ui/components/placeholders/Placeholder.kt @@ -136,6 +136,7 @@ fun Modifier.placeholder( val transitionState = remember { MutableTransitionState(visible) }.apply { targetState = visible } + // TODO resolve val transition = updateTransition(transitionState, "placeholder_crossfade") val placeholderAlpha by transition.animateFloat( diff --git a/build.gradle.kts b/build.gradle.kts index 417bdf72..f4dd1f2e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved * * This file is part of Menza. * @@ -23,6 +23,7 @@ import org.jlleitschuh.gradle.ktlint.KtlintExtension plugins { alias(libs.plugins.kotlin.android) apply false alias(libs.plugins.kotlin.jvm) apply false + alias(libs.plugins.kotlin.compose.compiler) apply false alias(libs.plugins.kotlin.multiplatform) apply false alias(libs.plugins.kotlin.serialization) apply false alias(libs.plugins.kotlin.parcelize) apply false diff --git a/gradle.properties b/gradle.properties index c81807d9..b7620d44 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # -# Copyright 2023, Petr La?tovi?ka as Lasta apps, All rights reserved +# Copyright 2024, Petr La?tovi?ka as Lasta apps, All rights reserved # # This file is part of Menza. # @@ -22,7 +22,6 @@ android.enableJetifier=false android.nonTransitiveRClass=true android.useAndroidX=true kotlin.code.style=official -kotlin.experimental.tryK2=true kotlin.mpp.androidGradlePluginCompatibility.nowarn=true kotlin.mpp.androidSourceSetLayoutVersion=2 kotlin.mpp.stability.nowarn=true diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 74c274ca..35cebe26 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -3,8 +3,6 @@ aboutLibraries = "11.1.4" android-gradle = "8.3.2" androidx-activity = "1.9.0" androidx-compose = "1.7.0-beta01" -# @keep -androidx-compose-compiler = "1.5.14" androidx-compose-material = "1.7.0-beta01" androidx-compose-material3 = "1.3.0-beta01" androidx-lifecycle = "2.8.0" @@ -22,7 +20,7 @@ kermit = "2.0.3" koin = "3.5.6" koin-annotations = "1.0.3" kotest = "5.8.0" -kotlin = "1.9.24" +kotlin = "2.0.0" # @keep kotlin-api = "2.0" # @keep @@ -48,7 +46,6 @@ androidx-annotation = "androidx.annotation:annotation:1.8.0" androidx-appcompat = "androidx.appcompat:appcompat:1.7.0-rc01" androidx-collection = "androidx.collection:collection:1.4.0" androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose" } -androidx-compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "androidx-compose-compiler" } androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose" } androidx-compose-iconsCore = { module = "androidx.compose.material:material-icons-core", version.ref = "androidx-compose-material" } androidx-compose-iconsExtended = { module = "androidx.compose.material:material-icons-extended", version.ref = "androidx-compose-material" } @@ -109,6 +106,7 @@ google-material = "com.google.android.material:material:1.12.0" gradlePlugins-android = { module = "com.android.tools.build:gradle", version.ref = "android-gradle" } gradlePlugins-detekt = { module = "io.gitlab.arturbosch.detekt:detekt-gradle-plugin", version.ref = "detekt" } gradlePlugins-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +gradlePlugins-kotlin-compose-compiler = { module = "org.jetbrains.kotlin:compose-compiler-gradle-plugin", version.ref = "kotlin" } gradlePlugins-ktlint = { module = "org.jlleitschuh.gradle:ktlint-gradle", version.ref = "ktlint" } gradlePlugins-shadow = { module = "gradle.plugin.com.github.johnrengelman:shadow", version.ref = "shadow" } junit5-bom = { module = "org.junit:junit-bom", version.ref = "junit5-bom" } @@ -231,16 +229,16 @@ java-library = { id = "java-library" } kapt = "org.jetbrains.kotlin:kotlin-kapt" kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-atomicfu = { id = "org.jetbrains.kotlin.plugin.atomicfu", version.ref = "kotlin" } +kotlin-compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } kotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" } kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlint" } -lastaapps-android-app-compose = "android-app-compose-convention:none" -lastaapps-android-app-core = "android-app-convention:none" -lastaapps-android-library-compose = "android-library-compose-convention:none" -lastaapps-android-library-core = "android-library-convention:none" +lastaapps-android-app = "android-app-convention:none" +lastaapps-android-library = "android-library-convention:none" lastaapps-common-coil = "common-coil-convention:none" +lastaapps-common-compose = "common-compose-convention:none" lastaapps-jvm-app = "jvm-app-convention:none" lastaapps-kmp-library = "kmp-library-convention:none" lastaapps-kmp-sqldelight = "kmp-sqldelight-convention:none" diff --git a/gradle/plugins/convention/build.gradle.kts b/gradle/plugins/convention/build.gradle.kts index 384f44ec..9a6b3833 100644 --- a/gradle/plugins/convention/build.gradle.kts +++ b/gradle/plugins/convention/build.gradle.kts @@ -41,6 +41,7 @@ kotlin { dependencies { implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) compileOnly(libs.gradlePlugins.kotlin) + compileOnly(libs.gradlePlugins.kotlin.compose.compiler) compileOnly(libs.gradlePlugins.android) compileOnly(libs.gradlePlugins.ktlint) implementation(libs.gradlePlugins.detekt) @@ -50,20 +51,16 @@ gradlePlugin { plugins { val ids = libs.plugins.lastaapps plugin( - ids.android.app.core, - pkg("android.AndroidAppConvention") + ids.android.app, + pkg("android.AndroidAppConvention"), ) plugin( - ids.android.app.compose, - pkg("android.AndroidAppComposeConvention") + ids.android.library, + pkg("android.AndroidLibraryConvention"), ) plugin( - ids.android.library.core, - pkg("android.AndroidLibraryConvention") - ) - plugin( - ids.android.library.compose, - pkg("android.AndroidLibraryComposeConvention"), + ids.common.compose, + pkg("common.ComposeConvention"), ) plugin( ids.common.coil, diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/DependencyExtensions.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/DependencyExtensions.kt index 085f75f9..8c5ed6d4 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/DependencyExtensions.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/DependencyExtensions.kt @@ -21,12 +21,9 @@ package cz.lastaapps.extensions -import com.android.build.gradle.BaseExtension -import org.gradle.api.Action import org.gradle.api.artifacts.ExternalModuleDependency import org.gradle.api.provider.Provider import org.gradle.kotlin.dsl.DependencyHandlerScope -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions fun DependencyHandlerScope.implementation( dependency: String, @@ -63,6 +60,3 @@ fun DependencyHandlerScope.coreLibraryDesugaring(dependencyNotation: Any) = fun DependencyHandlerScope.ksp(dependencyNotation: Any) = add(Constants.KSP, dependencyNotation) - -fun BaseExtension.kotlinOptions(configure: Action) = - (this as org.gradle.api.plugins.ExtensionAware).extensions.configure("kotlinOptions", configure) diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/PojectExtensions.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/PojectExtensions.kt index 18a1b4df..74d7f106 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/PojectExtensions.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/extensions/PojectExtensions.kt @@ -24,13 +24,19 @@ import com.android.build.gradle.LibraryExtension import com.android.build.gradle.internal.dsl.BaseAppModuleExtension import org.gradle.api.Action import org.gradle.api.Project -import org.gradle.api.plugins.ExtensionAware import org.gradle.api.plugins.JavaPluginExtension import org.gradle.api.plugins.PluginManager import org.gradle.api.provider.Provider +import org.gradle.kotlin.dsl.findByType +import org.gradle.kotlin.dsl.getByType import org.gradle.kotlin.dsl.the import org.gradle.plugin.use.PluginDependency -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions +import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi +import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinCommonProjectExtension +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions +import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension @@ -51,10 +57,6 @@ fun Project.pluginManager(block: PluginManager.() -> Unit) { pluginManager.apply(block) } -fun CommonExtension<*, *, *, *, *, *>.kotlinOptions(block: KotlinJvmOptions.() -> Unit) { - (this as ExtensionAware).extensions.configure("kotlinOptions", block) -} - fun Project.android(block: CommonExtension<*, *, *, *, *, *>.() -> Unit) { extension("android", block) } @@ -72,6 +74,48 @@ fun Project.java(block: JavaPluginExtension.() -> Unit) { extension("java", block) } +@OptIn(ExperimentalKotlinGradlePluginApi::class) +fun Project.compilerOptions( + jvmAndroid: KotlinJvmCompilerOptions.() -> Unit = {}, + common: KotlinCommonCompilerOptions.() -> Unit, +) { + var anySucceed = false + + extensions.findByType()?.apply { + compilerOptions { + common() + jvmAndroid() + } + }?.also { anySucceed = true } + + extensions.findByType()?.apply { + compilerOptions { + common() + jvmAndroid() + } + }?.also { anySucceed = true } + + extensions.findByType()?.apply { + compilerOptions { + common() + } + }?.also { anySucceed = true } + + extensions.findByType()?.apply { + target { + compilerOptions { + common() + jvmAndroid() + } + } + }?.also { anySucceed = true } + + if (!anySucceed) { + // this will crash + extensions.getByType() + } +} + inline fun Project.extension(name: String, block: Action) { extensions.configure(name, block) // extensions.findByName(name)?.let { it as? T }?.apply(block) diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppComposeConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppComposeConvention.kt deleted file mode 100644 index f43c4956..00000000 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppComposeConvention.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved - * - * This file is part of Menza. - * - * Menza is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Menza is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Menza. If not, see . - */ - -package cz.lastaapps.plugin.android - -import cz.lastaapps.extensions.androidApp -import cz.lastaapps.plugin.BasePlugin -import cz.lastaapps.plugin.android.config.configureComposeCompiler -import cz.lastaapps.plugin.android.config.configureComposeDependencies -import org.gradle.kotlin.dsl.apply - -@Suppress("unused") -class AndroidAppComposeConvention : BasePlugin({ - - apply() - - androidApp { - configureComposeCompiler(this) - } - configureComposeDependencies() -}) \ No newline at end of file diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppConvention.kt index 70ae1d08..3177a940 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidAppConvention.kt @@ -103,9 +103,11 @@ class AndroidAppConvention : BasePlugin( } packaging { - resources { } + resources { + // TODO Remove after skrape-it is removed + excludes.add("META-INF/INDEX.LIST") + } } - } apply() diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidKspConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidKspConvention.kt index a6af6067..a0fd1c01 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidKspConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidKspConvention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved * * This file is part of Menza. * @@ -25,6 +25,7 @@ import cz.lastaapps.extensions.pluginManager import cz.lastaapps.plugin.BasePlugin import org.jetbrains.kotlin.gradle.dsl.kotlinExtension +@Suppress("unused") class AndroidKspConvention : BasePlugin({ pluginManager { alias(libs.plugins.google.ksp) diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryComposeConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryComposeConvention.kt deleted file mode 100644 index bd0bf880..00000000 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryComposeConvention.kt +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved - * - * This file is part of Menza. - * - * Menza is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Menza is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Menza. If not, see . - */ - -package cz.lastaapps.plugin.android - -import com.android.build.api.dsl.LibraryExtension -import cz.lastaapps.plugin.BasePlugin -import cz.lastaapps.plugin.android.config.configureComposeCompiler -import cz.lastaapps.plugin.android.config.configureComposeDependencies -import org.gradle.kotlin.dsl.apply -import org.gradle.kotlin.dsl.configure - -@Suppress("unused") -class AndroidLibraryComposeConvention : BasePlugin({ - apply() - - extensions.configure { - configureComposeCompiler(this) - } - configureComposeDependencies() -}) \ No newline at end of file diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryConvention.kt index 76c364de..3ff0ef6d 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/AndroidLibraryConvention.kt @@ -1,5 +1,5 @@ /* - * Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved * * This file is part of Menza. * @@ -25,7 +25,6 @@ import cz.lastaapps.extensions.implementation import cz.lastaapps.extensions.libs import cz.lastaapps.extensions.pluginManager import cz.lastaapps.plugin.BasePlugin -import cz.lastaapps.plugin.android.config.configureComposeCompiler import cz.lastaapps.plugin.android.config.configureKotlinAndroid import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.configure @@ -43,7 +42,6 @@ class AndroidLibraryConvention : BasePlugin({ extensions.configure { configureKotlinAndroid(this) - configureComposeCompiler(this) defaultConfig { multiDexEnabled = true } diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/CoroutinesConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/CoroutinesConvention.kt index 18ed1ba2..538f5e04 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/CoroutinesConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/CoroutinesConvention.kt @@ -19,23 +19,22 @@ package cz.lastaapps.plugin.android.common +import cz.lastaapps.extensions.compilerOptions import cz.lastaapps.extensions.implementation import cz.lastaapps.extensions.libs import cz.lastaapps.extensions.testImplementation import cz.lastaapps.plugin.BasePlugin import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile class CoroutinesConvention : BasePlugin( { - tasks.withType { - kotlinOptions { - freeCompilerArgs += listOf( + compilerOptions { + freeCompilerArgs.addAll( + listOf( "-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi", "-opt-in=kotlinx.coroutines.FlowPreview", - ) - } + ), + ) } dependencies { diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/KotlinBaseConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/KotlinBaseConvention.kt index a33bebaa..0653a3b7 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/KotlinBaseConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/common/KotlinBaseConvention.kt @@ -21,6 +21,7 @@ package cz.lastaapps.plugin.android.common import cz.lastaapps.extensions.alias import cz.lastaapps.extensions.android +import cz.lastaapps.extensions.compilerOptions import cz.lastaapps.extensions.implementation import cz.lastaapps.extensions.java import cz.lastaapps.extensions.libs @@ -30,12 +31,12 @@ import org.gradle.api.JavaVersion import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.apply import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + +private typealias KV = org.jetbrains.kotlin.gradle.dsl.KotlinVersion class KotlinBaseConvention : BasePlugin( { - pluginManager { alias(libs.plugins.kotlin.serialization) } @@ -54,17 +55,21 @@ class KotlinBaseConvention : BasePlugin( android { } - tasks.withType { - kotlinOptions { - languageVersion = libs.versions.kotlin.language.get() - apiVersion = libs.versions.kotlin.api.get() + compilerOptions( + { + val versionCode = libs.versions.java.jvmTarget.get().toInt() + val version = JavaVersion.toVersion(versionCode) + jvmTarget.set(JvmTarget.fromTarget(version.toString())) + }, + ) { + languageVersion.set(KV.fromVersion(libs.versions.kotlin.language.get())) + apiVersion.set(KV.fromVersion(libs.versions.kotlin.api.get())) - freeCompilerArgs += listOf( + freeCompilerArgs.addAll( + listOf( "-opt-in=kotlin.ExperimentalStdlibApi", - "-opt-in=kotlin.time.ExperimentalTime", - "-Xcontext-receivers", - ) - } + ), + ) } dependencies { diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/ComposeConfig.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/ComposeConfig.kt deleted file mode 100644 index 7b839f40..00000000 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/ComposeConfig.kt +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved - * - * This file is part of Menza. - * - * Menza is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Menza is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Menza. If not, see . - */ - -package cz.lastaapps.plugin.android.config - -import com.android.build.api.dsl.CommonExtension -import cz.lastaapps.extensions.alias -import cz.lastaapps.extensions.debugImplementation -import cz.lastaapps.extensions.implementation -import cz.lastaapps.extensions.libs -import cz.lastaapps.extensions.pluginManager -import org.gradle.api.Project -import org.gradle.kotlin.dsl.dependencies - - -internal fun Project.configureComposeCompiler( - commonExtension: CommonExtension<*, *, *, *, *, *>, -) = with(commonExtension) { - buildFeatures { - compose = true - } - - composeOptions { - kotlinCompilerExtensionVersion = libs.versions.androidx.compose.compiler.get() - } -} - -internal fun Project.configureComposeDependencies() { - pluginManager { - // Required by Decompose - alias(libs.plugins.kotlin.serialization) - } - - dependencies { - - implementation(libs.google.material) - - implementation(libs.androidx.activity.compose) - implementation(libs.androidx.constraintlayout.compose) - implementation(libs.androidx.compose.material3) - implementation(libs.androidx.compose.material3WindowSizeClass) - implementation(libs.androidx.compose.iconsCore) - implementation(libs.androidx.compose.iconsExtended) - implementation(libs.androidx.compose.animation) - implementation(libs.androidx.compose.ui.util) - debugImplementation(libs.androidx.compose.tooling) - implementation(libs.androidx.compose.toolingPreview) - - implementation(libs.androidx.lifecycle.runtime.asProvider()) - implementation(libs.androidx.lifecycle.runtime.compose) - - implementation(libs.decompose.core) - implementation(libs.decompose.compose) - - implementation(libs.coil.compose.complete) - } -} diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/KoltinAndroidConfig.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/KoltinAndroidConfig.kt index a5274160..b2b86d62 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/KoltinAndroidConfig.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/android/config/KoltinAndroidConfig.kt @@ -20,12 +20,13 @@ package cz.lastaapps.plugin.android.config import com.android.build.api.dsl.CommonExtension +import cz.lastaapps.extensions.compilerOptions import cz.lastaapps.extensions.coreLibraryDesugaring import cz.lastaapps.extensions.implementation -import cz.lastaapps.extensions.kotlinOptions import cz.lastaapps.extensions.libs import org.gradle.api.JavaVersion import org.gradle.api.Project +import org.gradle.kotlin.dsl.assign import org.gradle.kotlin.dsl.dependencies internal fun Project.configureKotlinAndroid( @@ -39,17 +40,16 @@ internal fun Project.configureKotlinAndroid( testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" } - try { - kotlinOptions { - // Treat all Kotlin warnings as errors (disabled by default) - allWarningsAsErrors = properties["warningsAsErrors"] as? Boolean ?: false + compilerOptions { + // Treat all Kotlin warnings as errors (disabled by default) + allWarningsAsErrors = properties["warningsAsErrors"] as? Boolean ?: false - freeCompilerArgs = freeCompilerArgs + listOf( + freeCompilerArgs.addAll( + listOf( "-opt-in=kotlin.RequiresOptIn", "-Xcontext-receivers", - ) - } - } catch (_: Exception) { + ), + ) } compileOptions { diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/common/ComposeConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/common/ComposeConvention.kt new file mode 100644 index 00000000..00060958 --- /dev/null +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/common/ComposeConvention.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved + * + * This file is part of Menza. + * + * Menza is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Menza is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Menza. If not, see . + */ + +package cz.lastaapps.plugin.common + +import cz.lastaapps.extensions.alias +import cz.lastaapps.extensions.debugImplementation +import cz.lastaapps.extensions.implementation +import cz.lastaapps.extensions.libs +import cz.lastaapps.extensions.pluginManager +import cz.lastaapps.plugin.BasePlugin +import org.gradle.kotlin.dsl.assign +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.getByType +import org.jetbrains.kotlin.compose.compiler.gradle.ComposeCompilerGradlePluginExtension + +class ComposeConvention : BasePlugin( + { + pluginManager { + alias(libs.plugins.kotlin.compose.compiler) + // Required by Decompose + alias(libs.plugins.kotlin.serialization) + } + + with(extensions.getByType()) { + enableStrongSkippingMode = true + includeSourceInformation = true + enableNonSkippingGroupOptimization = true + } + + dependencies { + implementation(libs.google.material) + + implementation(libs.androidx.activity.compose) + implementation(libs.androidx.constraintlayout.compose) + implementation(libs.androidx.compose.material3) + implementation(libs.androidx.compose.material3WindowSizeClass) + implementation(libs.androidx.compose.iconsCore) + implementation(libs.androidx.compose.iconsExtended) + implementation(libs.androidx.compose.animation) + implementation(libs.androidx.compose.ui.util) + debugImplementation(libs.androidx.compose.tooling) + implementation(libs.androidx.compose.toolingPreview) + + implementation(libs.androidx.lifecycle.runtime.asProvider()) + implementation(libs.androidx.lifecycle.runtime.compose) + + implementation(libs.decompose.core) + implementation(libs.decompose.compose) + + implementation(libs.coil.compose.complete) + } + }, +) \ No newline at end of file diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/jvm/JvmAppConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/jvm/JvmAppConvention.kt index 9731e674..d059e26a 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/jvm/JvmAppConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/jvm/JvmAppConvention.kt @@ -25,6 +25,7 @@ import cz.lastaapps.extensions.libs import cz.lastaapps.extensions.pluginManager import cz.lastaapps.extensions.testImplementation import cz.lastaapps.plugin.BasePlugin +import cz.lastaapps.plugin.android.common.KotlinBaseConvention import cz.lastaapps.plugin.common.ArrowKtConvention import cz.lastaapps.plugin.common.DetektConvention import org.gradle.api.tasks.testing.Test @@ -33,7 +34,6 @@ import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.withType import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import org.jetbrains.kotlin.gradle.dsl.kotlinExtension -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @Suppress("unused") class JvmAppConvention : BasePlugin( @@ -44,18 +44,13 @@ class JvmAppConvention : BasePlugin( alias(libs.plugins.shadow) } + apply() apply() apply() tasks.withType { useJUnitPlatform() } - tasks.withType { - kotlinOptions { - languageVersion = libs.versions.kotlin.language.get() - apiVersion = libs.versions.kotlin.api.get() - } - } (kotlinExtension as KotlinJvmProjectExtension).apply { sourceSets.all { diff --git a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/multiplatform/KMPLibraryConvention.kt b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/multiplatform/KMPLibraryConvention.kt index 031bdcea..d1858baf 100644 --- a/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/multiplatform/KMPLibraryConvention.kt +++ b/gradle/plugins/convention/src/main/kotlin/cz/lastaapps/plugin/multiplatform/KMPLibraryConvention.kt @@ -30,6 +30,7 @@ import cz.lastaapps.plugin.android.AndroidLibraryConvention import cz.lastaapps.plugin.android.common.KotlinBaseConvention import cz.lastaapps.plugin.android.config.configureKotlinAndroid import cz.lastaapps.plugin.common.ArrowKtConvention +import cz.lastaapps.plugin.common.ComposeConvention import cz.lastaapps.plugin.common.DetektConvention import cz.lastaapps.plugin.common.JavaConvention import org.gradle.api.tasks.testing.Test @@ -38,7 +39,6 @@ import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.dependencies import org.gradle.kotlin.dsl.get import org.gradle.kotlin.dsl.withType -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @Suppress("unused") class KMPLibraryConvention : BasePlugin( @@ -49,68 +49,28 @@ class KMPLibraryConvention : BasePlugin( alias(libs.plugins.android.library) } - apply() apply() + apply() apply() apply() apply() + apply() extensions.configure { sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml") configureKotlinAndroid(this) -// configureComposeCompiler(this) - - // KMP plugin is fucking broken - // https://issuetracker.google.com/issues/155536223#comment7 - val composeCompilerDependency = libs.androidx.compose.compiler - dependencies { - val namePrefixAndroid = "kotlinCompilerPluginClasspathAndroid" - val namePrefixCommon = "kotlinCompilerPluginClasspathCommon" - configurations.configureEach { - if (name.startsWith(namePrefixAndroid) || name.startsWith(namePrefixCommon)) { - add(name, composeCompilerDependency) - } - } - } } tasks.withType { useJUnitPlatform() } - tasks.withType { - kotlinOptions { - languageVersion = libs.versions.kotlin.language.get() - apiVersion = libs.versions.kotlin.api.get() - } - } multiplatform { - - sourceSets.all { - languageSettings.apply { - optIn("kotlin.RequiresOptIn") - optIn("kotlinx.coroutines.ExperimentalCoroutinesApi") - languageVersion = libs.versions.kotlin.language.get() - apiVersion = libs.versions.kotlin.api.get() - } - } - - targets.all { - compilations.all { } - } - - androidTarget { - compilations.all { - kotlinOptions { } - } - } - jvm { - compilations.all { - kotlinOptions { } - } - } + targets.all {} + androidTarget { } + jvm {} sourceSets.apply { getByName("commonMain") { diff --git a/lastaapps/common/build.gradle.kts b/lastaapps/common/build.gradle.kts index e0368a33..6afe87b2 100644 --- a/lastaapps/common/build.gradle.kts +++ b/lastaapps/common/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2022, Petr Laštovička as Lasta apps, All rights reserved + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved * * This file is part of Menza. * @@ -22,7 +22,8 @@ import java.time.ZoneOffset.UTC import java.time.format.DateTimeFormatter plugins { - alias(libs.plugins.lastaapps.android.library.core) + alias(libs.plugins.lastaapps.android.library) + alias(libs.plugins.lastaapps.common.compose) `maven-publish` } diff --git a/lastaapps/crash/build.gradle.kts b/lastaapps/crash/build.gradle.kts index 2c17f39b..0b39a89a 100644 --- a/lastaapps/crash/build.gradle.kts +++ b/lastaapps/crash/build.gradle.kts @@ -1,5 +1,5 @@ /* - * Copyright 2023, Petr Laštovička as Lasta apps, All rights reserved + * Copyright 2024, Petr Laštovička as Lasta apps, All rights reserved * * This file is part of Menza. * @@ -18,7 +18,8 @@ */ plugins { - alias(libs.plugins.lastaapps.android.library.core) + alias(libs.plugins.lastaapps.android.library) + alias(libs.plugins.lastaapps.common.compose) alias(libs.plugins.sqldelight) }