Skip to content

Commit

Permalink
Merge pull request #5 from jfyoteau/feature/update_dependency
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
jfyoteau authored Sep 7, 2024
2 parents 49c7672 + 1ce2361 commit 9c24703
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 122 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.iml
.kotlin
.gradle
**/build/
xcuserdata
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package jfyoteau.noteapp.convention

import org.gradle.api.JavaVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget

object AndroidBuildConfig {
const val compileSdkVersion = 34
const val minSdkVersion = 29
const val targetSdkVersion = 34
val jvmTarget = JavaVersion.VERSION_17
const val COMPILE_SDK_VERSION = 34
const val MIN_SDK_VERSION = 29
const val TARGET_SDK_VERSION = 34
val jvmTarget = JvmTarget.JVM_17
val javaVersion = JavaVersion.VERSION_17
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ internal fun Project.configureAndroidCompose(
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion =
libs.findVersion("androidx-compose-compiler").get().toString()
}

dependencies {
val bom = libs.findLibrary("androidx-compose-bom").get()
add("implementation", platform(bom))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ internal fun Project.configureJetbrainsCompose(
kotlinMultiplatformExtension: KotlinMultiplatformExtension
) {
val composeExtension = extensions.getByType<ComposeExtension>()
composeExtension.apply {
kotlinCompilerPlugin.set(libs.findVersion("jetbrains.compose.compiler").get().toString())
}
val compose = composeExtension.dependencies

kotlinMultiplatformExtension.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal fun Project.configureKotlinAndroid(
val resFile = file("src/androidMain/res")

commonExtension.apply {
compileSdk = AndroidBuildConfig.compileSdkVersion
compileSdk = AndroidBuildConfig.COMPILE_SDK_VERSION

if (androidManifestFile.exists()) {
sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
Expand All @@ -27,14 +27,14 @@ internal fun Project.configureKotlinAndroid(
}

defaultConfig {
minSdk = AndroidBuildConfig.minSdkVersion
minSdk = AndroidBuildConfig.MIN_SDK_VERSION
}

compileOptions {
// Up to Java 11 APIs are available through desugaring
// https://developer.android.com/studio/write/java11-minimal-support-table
sourceCompatibility = AndroidBuildConfig.jvmTarget
targetCompatibility = AndroidBuildConfig.jvmTarget
sourceCompatibility = AndroidBuildConfig.javaVersion
targetCompatibility = AndroidBuildConfig.javaVersion
isCoreLibraryDesugaringEnabled = true
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package jfyoteau.noteapp.convention.configuration

import jfyoteau.noteapp.convention.AndroidBuildConfig
import org.gradle.jvm.toolchain.JavaLanguageVersion
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension

Expand All @@ -9,6 +10,10 @@ internal fun configureKotlinMultiplatform(
kotlinMultiplatformExtension: KotlinMultiplatformExtension
) {
kotlinMultiplatformExtension.apply {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(AndroidBuildConfig.javaVersion.majorVersion))
}

// https://kotlinlang.org/docs/multiplatform-expect-actual.html#expected-and-actual-classes
// To suppress this warning about usage of expected and actual classes
compilerOptions {
Expand All @@ -17,10 +22,8 @@ internal fun configureKotlinMultiplatform(

// Android
androidTarget {
compilations.all {
kotlinOptions {
jvmTarget = AndroidBuildConfig.jvmTarget.toString()
}
compilerOptions {
jvmTarget.set(AndroidBuildConfig.jvmTarget)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,33 @@ import jfyoteau.noteapp.convention.EnvParams
import org.gradle.internal.os.OperatingSystem
import org.jetbrains.kotlin.gradle.plugin.KotlinPlatformType
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMultiplatformPlugin
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinMetadataTarget

private enum class HostType {
MAC_OS,
LINUX,
}

private fun KotlinTarget.getHostType(): HostType? =
when (platformType) {
KotlinPlatformType.androidJvm,
KotlinPlatformType.jvm,
KotlinPlatformType.js,
KotlinPlatformType.wasm -> HostType.LINUX

KotlinPlatformType.native ->
when {
name.startsWith("ios") -> HostType.MAC_OS
name.startsWith("watchos") -> HostType.MAC_OS
name.startsWith("linux") -> HostType.LINUX
else -> error("Unsupported native target: $this")
}

KotlinPlatformType.common -> null
}
when (platformType) {
KotlinPlatformType.androidJvm,
KotlinPlatformType.jvm,
KotlinPlatformType.js,
KotlinPlatformType.wasm -> HostType.LINUX

KotlinPlatformType.native ->
when {
name.startsWith("ios") -> HostType.MAC_OS
name.startsWith("watchos") -> HostType.MAC_OS
name.startsWith("linux") -> HostType.LINUX
else -> error("Unsupported native target: $this")
}

KotlinPlatformType.common -> null
}

private fun KotlinTarget.isCompilationAllowed(): Boolean {
if ((name == KotlinMultiplatformPlugin.METADATA_TARGET_NAME) || !EnvParams.splitTargets) {
if ((name == KotlinMetadataTarget.METADATA_TARGET_NAME) || !EnvParams.splitTargets) {
return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class JetbrainsComposeConventionPlugins: Plugin<Project> {
with(target) {
with(pluginManager) {
apply("org.jetbrains.compose")
apply("org.jetbrains.kotlin.plugin.compose")
}

if (!pluginManager.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class KotlinMultiplatformApplicationConventionPlugin : Plugin<Project> {
// Configure Android Application
extensions.configure<ApplicationExtension> {
configureKotlinAndroid(this)
defaultConfig.targetSdk = AndroidBuildConfig.targetSdkVersion
defaultConfig.targetSdk = AndroidBuildConfig.TARGET_SDK_VERSION
}

// Because task 'testClasses' does not exist, create it
Expand Down
13 changes: 7 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
plugins {
// this is necessary to avoid the plugins to be loaded multiple times
// in each subproject's classloader
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.jetbrainsCompose) apply false
alias(libs.plugins.kotlinMultiplatform) apply false
alias(libs.plugins.kotlinSerialization) apply false
alias(libs.plugins.gradleVersions)
alias(libs.plugins.android.application) apply false
alias(libs.plugins.android.library) apply false
alias(libs.plugins.jetbrains.compose) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.compose.compiler) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.gradle.versions)
}

// ==========================================================================================
Expand Down
13 changes: 12 additions & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.util.Properties
plugins {
alias(libs.plugins.convention.kmp.application)
alias(libs.plugins.convention.jetbrainsCompose)
alias(libs.plugins.kotlinSerialization)
alias(libs.plugins.kotlin.serialization)
}

kotlin {
Expand All @@ -31,16 +31,20 @@ kotlin {
implementation(libs.decompose)
}
commonMain.dependencies {
implementation(projects.core.presentation)
implementation(projects.feature.splash)
implementation(projects.feature.note)
implementation(libs.koin.core)
implementation(libs.koin.compose)
implementation(libs.kotlinx.coroutines.core)
implementation(libs.decompose)
implementation(libs.decompose.extensions.compose)
}
desktopMain.dependencies {
implementation(compose.desktop.currentOs)
implementation(libs.kotlinx.coroutines.swing)
implementation(libs.slf4j.api)
implementation(libs.slf4j.reload4j)
}
}
}
Expand Down Expand Up @@ -87,10 +91,17 @@ compose.desktop {
application {
mainClass = "jfyoteau.noteapp.MainKt"

buildTypes.release {
proguard {
configurationFiles.from("compose-desktop.pro")
}
}

nativeDistributions {
targetFormats(TargetFormat.Dmg, TargetFormat.Msi, TargetFormat.Deb)
packageName = "jfyoteau.noteapp"
packageVersion = "1.0.0"
includeAllModules = true
}
}
}
14 changes: 14 additions & 0 deletions composeApp/compose-desktop.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# sl4j
-dontwarn javax.jms.**
-dontwarn javax.mail.**
-dontwarn com.sun.jdmk.comm.**

# kotlinx.coroutines
-keep class kotlinx.coroutines.internal.MainDispatcherFactory { *; }
-keep class kotlinx.coroutines.swing.SwingDispatcherFactory { *; }

# Decompose
-keep class com.arkivanov.decompose.extensions.compose.mainthread.SwingMainThreadChecker

# sqlite
-keep class org.sqlite.** { *; }
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import androidx.compose.foundation.gestures.Orientation
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.slide
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.stackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.arkivanov.decompose.extensions.compose.stack.Children
import com.arkivanov.decompose.extensions.compose.stack.animation.fade
import com.arkivanov.decompose.extensions.compose.stack.animation.slide
import com.arkivanov.decompose.extensions.compose.stack.animation.stackAnimation
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import jfyoteau.noteapp.note.presentation.notedetail.screen.NoteDetailScreen
import jfyoteau.noteapp.note.presentation.notelist.screen.NoteListScreen
import jfyoteau.noteapp.presentation.state.AppState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import jfyoteau.noteapp.splash.presentation.state.SplashState
interface AppState {
sealed interface Child {
data class Splash(val state: SplashState) : Child

data class NoteList(val state: NoteListState) : Child

data class NoteDetail(val state: NoteDetailState, val isNew: Boolean) : Child
}

Expand Down
4 changes: 1 addition & 3 deletions composeApp/src/desktopMain/kotlin/jfyoteau/noteapp/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import androidx.compose.ui.window.Window
import androidx.compose.ui.window.application
import androidx.compose.ui.window.rememberWindowState
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.extensions.compose.jetbrains.lifecycle.LifecycleController
import com.arkivanov.decompose.extensions.compose.lifecycle.LifecycleController
import com.arkivanov.essenty.lifecycle.LifecycleRegistry
import jfyoteau.noteapp.di.GetAppState
import jfyoteau.noteapp.di.initKoin
import jfyoteau.noteapp.presentation.screen.App

@OptIn(ExperimentalDecomposeApi::class)
fun main() {
// Initialize Koin
initKoin()
Expand Down
2 changes: 1 addition & 1 deletion composeApp/src/iosMain/kotlin/MainViewController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.window.ComposeUIViewController
import com.arkivanov.decompose.DefaultComponentContext
import com.arkivanov.decompose.ExperimentalDecomposeApi
import com.arkivanov.decompose.lifecycle.ApplicationLifecycle
import com.arkivanov.essenty.lifecycle.ApplicationLifecycle
import jfyoteau.noteapp.presentation.screen.App
import jfyoteau.noteapp.di.GetAppState

Expand Down
40 changes: 2 additions & 38 deletions core/resources/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,6 @@ android {
namespace = "jfyoteau.noteapp.core.resources"
}

// fix for [https://github.com/JetBrains/compose-multiplatform/issues/4327]
// After executing the "generateComposeResClass" task, we replace the internal stuff by public.
tasks.named("generateComposeResClass") {
doLast {
val dirName = buildString {
val group = project.group.toString()
.lowercase()
.replace('.', '/')
.replace('-', '_')
append(group)
if (group.isNotEmpty()) {
append("/")
}
append(project.name.lowercase())
}
val dir = project.layout.buildDirectory
.dir("generated/compose/resourceGenerator/kotlin/$dirName/generated/resources")
.get()
.asFile
File(dir, "Res.kt").also {
if (!it.exists()) {
return@also
}
val content = it.readText()
val updatedContent = content.replace("internal object Res {", "object Res {")
it.writeText(updatedContent)
}
listOf("Drawable0.kt", "String0.kt").forEach { filename ->
File(dir, filename).also { file ->
if (!file.exists()) {
return@also
}
val content = file.readText()
val updatedContent = content.replace("internal val Res", "val Res")
file.writeText(updatedContent)
}
}
}
compose.resources {
publicResClass = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import jfyoteau.noteapp.note.domain.model.Note
import jfyoteau.noteapp.note.presentation.notedetail.state.NoteDetailState
import jfyoteau.noteapp.note.presentation.notedetail.state.NoteDetailUiEvent
Expand All @@ -55,11 +55,10 @@ import noteapp.core.resources.generated.resources.icon_close
import noteapp.core.resources.generated.resources.icon_save
import noteapp.core.resources.generated.resources.note
import noteapp.core.resources.generated.resources.save_note
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalMaterial3Api::class, ExperimentalResourceApi::class)
@OptIn(ExperimentalMaterial3Api::class,)
@Composable
fun NoteDetailScreen(state: NoteDetailState) {
val uiState by state.uiState.subscribeAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.extensions.compose.jetbrains.subscribeAsState
import com.arkivanov.decompose.extensions.compose.subscribeAsState
import jfyoteau.noteapp.note.presentation.notelist.state.NoteListState
import jfyoteau.noteapp.note.presentation.notelist.state.NoteListUiEvent
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -44,12 +44,10 @@ import noteapp.core.resources.generated.resources.icon_sort
import noteapp.core.resources.generated.resources.note_deleted
import noteapp.core.resources.generated.resources.undo
import noteapp.core.resources.generated.resources.your_note
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.getString
import org.jetbrains.compose.resources.painterResource
import org.jetbrains.compose.resources.stringResource

@OptIn(ExperimentalResourceApi::class)
@Composable
fun NoteListScreen(state: NoteListState) {
val uiState by state.uiState.subscribeAsState()
Expand Down
Loading

0 comments on commit 9c24703

Please sign in to comment.