Skip to content

Commit

Permalink
build: Kotlin 2.0, compose, convention plugins rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Lastaapps committed Jul 2, 2024
1 parent 16ef717 commit 9eecc45
Show file tree
Hide file tree
Showing 24 changed files with 199 additions and 278 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
local.properties
/gradle/libs.versions.updates.toml
/.idea/other.xml
.kotlin
12 changes: 6 additions & 6 deletions api/agata/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -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.
#
Expand All @@ -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
Expand Down
14 changes: 6 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand All @@ -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" }
Expand Down Expand Up @@ -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" }
Expand Down Expand Up @@ -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"
Expand Down
17 changes: 7 additions & 10 deletions gradle/plugins/convention/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -63,6 +60,3 @@ fun DependencyHandlerScope.coreLibraryDesugaring(dependencyNotation: Any) =

fun DependencyHandlerScope.ksp(dependencyNotation: Any) =
add(Constants.KSP, dependencyNotation)

fun BaseExtension.kotlinOptions(configure: Action<KotlinJvmOptions>) =
(this as org.gradle.api.plugins.ExtensionAware).extensions.configure("kotlinOptions", configure)
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
}
Expand All @@ -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<KotlinAndroidProjectExtension>()?.apply {
compilerOptions {
common()
jvmAndroid()
}
}?.also { anySucceed = true }

extensions.findByType<KotlinJvmProjectExtension>()?.apply {
compilerOptions {
common()
jvmAndroid()
}
}?.also { anySucceed = true }

extensions.findByType<KotlinMultiplatformExtension>()?.apply {
compilerOptions {
common()
}
}?.also { anySucceed = true }

extensions.findByType<KotlinCommonProjectExtension>()?.apply {
target {
compilerOptions {
common()
jvmAndroid()
}
}
}?.also { anySucceed = true }

if (!anySucceed) {
// this will crash
extensions.getByType<KotlinCommonProjectExtension>()
}
}

inline fun <reified T : Any> Project.extension(name: String, block: Action<T>) {
extensions.configure(name, block)
// extensions.findByName(name)?.let { it as? T }?.apply(block)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ class AndroidAppConvention : BasePlugin(
}

packaging {
resources { }
resources {
// TODO Remove after skrape-it is removed
excludes.add("META-INF/INDEX.LIST")
}
}

}

apply<AndroidBaseConvention>()
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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)
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -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
Expand All @@ -43,7 +42,6 @@ class AndroidLibraryConvention : BasePlugin({

extensions.configure<LibraryExtension> {
configureKotlinAndroid(this)
configureComposeCompiler(this)
defaultConfig {
multiDexEnabled = true
}
Expand Down
Loading

0 comments on commit 9eecc45

Please sign in to comment.