diff --git a/.gitignore b/.gitignore index 2d7fd3986ed..c068a687c39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea +.vscode .kotlin out/* *.iml diff --git a/CHANGELOG.md b/CHANGELOG.md index 88d4c415e4f..6e8e7c28f25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,19 @@ # Changelog +## 0.26.0 + +**WARNING!!! SINCE THIS VERSION IF YOU WANT TO USE SOME OF KSP MODULES, SET `ksp.useKSP2=false` IN YOUR `gradle.properties`** (see [gh issue 2491](https://github.com/google/ksp/issues/2491)) + +* `Versions`: + * `Kotlin`: `2.1.21` -> `2.2.0` + * `Serialization`: `1.8.1` -> `1.9.0` + * `KSLog`: `1.4.2` -> `1.5.0` + * `Ktor`: `3.1.3` -> `3.2.1` + * `Koin`: `4.0.4` -> `4.1.0` + * `Okio`: `3.12.0` -> `3.15.0` + * `KSP`: `2.1.20-1.0.31` -> `2.2.0-2.0.2` + * `kotlin-poet`: `1.18.1` -> `2.2.0` + ## 0.25.8 * `Pagination`: diff --git a/build.gradle b/build.gradle index 4d1377d9504..ef380d4d69c 100644 --- a/build.gradle +++ b/build.gradle @@ -28,7 +28,7 @@ if ((project.hasProperty('SONATYPE_USER') || System.getenv('SONATYPE_USER') != n centralPortal { username = project.hasProperty('SONATYPE_USER') ? project.property('SONATYPE_USER') : System.getenv('SONATYPE_USER') password = project.hasProperty('SONATYPE_PASSWORD') ? project.property('SONATYPE_PASSWORD') : System.getenv('SONATYPE_PASSWORD') - verificationTimeout = Duration.ofHours(4) + validationTimeout = Duration.ofHours(4) publishingType = System.getenv('PUBLISHING_TYPE') != "" ? System.getenv('PUBLISHING_TYPE') : "USER_MANAGED" } diff --git a/common/src/jsMain/kotlin/dev/inmo/micro_utils/common/toFixed.kt b/common/src/jsMain/kotlin/dev/inmo/micro_utils/common/ToFixed.kt similarity index 100% rename from common/src/jsMain/kotlin/dev/inmo/micro_utils/common/toFixed.kt rename to common/src/jsMain/kotlin/dev/inmo/micro_utils/common/ToFixed.kt diff --git a/gradle.properties b/gradle.properties index 1ac852a2c89..6c9704f1421 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,6 +8,9 @@ android.useAndroidX=true android.enableJetifier=true org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=2g +# https://github.com/google/ksp/issues/2491 +ksp.useKSP2=false + # JS NPM crypto_js_version=4.1.1 @@ -15,5 +18,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.25.8 -android_code_version=298 +version=0.26.0 +android_code_version=299 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6af6465a38c..6461f4f4eaa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,12 +1,12 @@ [versions] -kt = "2.1.21" -kt-serialization = "1.8.1" +kt = "2.2.0" +kt-serialization = "1.9.0" kt-coroutines = "1.10.2" kotlinx-browser = "0.3" -kslog = "1.4.2" +kslog = "1.5.0" jb-compose = "1.8.1" jb-exposed = "0.61.0" @@ -17,19 +17,19 @@ sqlite = "3.50.1.0" korlibs = "5.4.0" uuid = "0.8.4" -ktor = "3.1.3" +ktor = "3.2.1" gh-release = "2.5.2" -koin = "4.0.4" +koin = "4.1.0" -okio = "3.12.0" +okio = "3.15.0" -ksp = "2.1.20-1.0.31" -kotlin-poet = "1.18.1" +ksp = "2.2.0-2.0.2" +kotlin-poet = "2.2.0" versions = "0.51.0" -nmcp = "0.1.5" +nmcp = "1.0.1" android-gradle = "8.9.+" dexcount = "4.0.0" diff --git a/koin/generator/build.gradle b/koin/generator/build.gradle index de6d7d1abec..6a3ea8343db 100644 --- a/koin/generator/build.gradle +++ b/koin/generator/build.gradle @@ -10,6 +10,7 @@ repositories { dependencies { api project(":micro_utils.koin") + api project(":micro_utils.ksp.generator") api libs.kotlin.poet api libs.ksp } diff --git a/koin/generator/src/main/kotlin/Processor.kt b/koin/generator/src/main/kotlin/Processor.kt index ed77e14d7d1..6933cafb563 100644 --- a/koin/generator/src/main/kotlin/Processor.kt +++ b/koin/generator/src/main/kotlin/Processor.kt @@ -26,6 +26,7 @@ import com.squareup.kotlinpoet.asTypeName import com.squareup.kotlinpoet.ksp.toClassName import com.squareup.kotlinpoet.ksp.toTypeName import com.squareup.kotlinpoet.ksp.writeTo +import dev.inmo.micro_ksp.generator.safeClassName import dev.inmo.micro_utils.koin.annotations.GenerateGenericKoinDefinition import dev.inmo.micro_utils.koin.annotations.GenerateKoinDefinition import org.koin.core.Koin @@ -237,15 +238,7 @@ class Processor( """.trimIndent() ) ksFile.getAnnotationsByType(GenerateKoinDefinition::class).forEach { - val type = runCatching { - it.type.asTypeName() - }.getOrElse { e -> - if (e is KSTypeNotPresentException) { - e.ksType.toClassName() - } else { - throw e - } - } + val type = safeClassName { it.type } val targetType = runCatching { type.parameterizedBy(*(it.typeArgs.takeIf { it.isNotEmpty() } ?.map { it.asTypeName() } ?.toTypedArray() ?: return@runCatching type)) }.getOrElse { e -> diff --git a/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt b/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt index 0ec0aea444a..c99a95472b3 100644 --- a/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt +++ b/koin/generator/test/src/commonMain/kotlin/GeneratedDefinitionsTest.kt @@ -5,7 +5,6 @@ package dev.inmo.micro_utils.koin.generator.test import kotlin.Any import kotlin.Boolean -import kotlin.Deprecated import kotlin.String import org.koin.core.Koin import org.koin.core.definition.Definition @@ -30,95 +29,59 @@ public val Koin.sampleInfo: Test /** * @return Definition by key "sampleInfo" with [parameters] */ -public inline fun Scope.sampleInfo(noinline parameters: ParametersDefinition): Test = - get(named("sampleInfo"), parameters) +public inline fun Scope.sampleInfo(noinline parameters: ParametersDefinition): Test = get(named("sampleInfo"), parameters) /** * @return Definition by key "sampleInfo" with [parameters] */ -public inline fun Koin.sampleInfo(noinline parameters: ParametersDefinition): Test = - get(named("sampleInfo"), parameters) +public inline fun Koin.sampleInfo(noinline parameters: ParametersDefinition): Test = get(named("sampleInfo"), parameters) /** * Will register [definition] with [org.koin.core.module.Module.single] and key "sampleInfo" */ -@Deprecated( - "This definition is old style and should not be used anymore. Use singleSampleInfo instead", - ReplaceWith("singleSampleInfo"), -) -public fun Module.sampleInfoSingle(createdAtStart: Boolean = false, - definition: Definition>): KoinDefinition> = - single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition) - -/** - * Will register [definition] with [org.koin.core.module.Module.single] and key "sampleInfo" - */ -public fun Module.singleSampleInfo(createdAtStart: Boolean = false, - definition: Definition>): KoinDefinition> = - single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition) +public fun Module.singleSampleInfo(createdAtStart: Boolean = false, definition: Definition>): KoinDefinition> = single(named("sampleInfo"), createdAtStart = createdAtStart, definition = definition) /** * Will register [definition] with [org.koin.core.module.Module.factory] and key "sampleInfo" */ -@Deprecated( - "This definition is old style and should not be used anymore. Use factorySampleInfo instead", - ReplaceWith("factorySampleInfo"), -) -public fun Module.sampleInfoFactory(definition: Definition>): - KoinDefinition> = factory(named("sampleInfo"), definition = definition) - -/** - * Will register [definition] with [org.koin.core.module.Module.factory] and key "sampleInfo" - */ -public fun Module.factorySampleInfo(definition: Definition>): - KoinDefinition> = factory(named("sampleInfo"), definition = definition) +public fun Module.factorySampleInfo(definition: Definition>): KoinDefinition> = factory(named("sampleInfo"), definition = definition) /** * @return Definition by key "test" with [parameters] */ -public inline fun Scope.test(noinline parameters: ParametersDefinition? = null): T - = get(named("test"), parameters) +public inline fun Scope.test(noinline parameters: ParametersDefinition? = null): T = get(named("test"), parameters) /** * @return Definition by key "test" with [parameters] */ -public inline fun Koin.test(noinline parameters: ParametersDefinition? = null): T - = get(named("test"), parameters) +public inline fun Koin.test(noinline parameters: ParametersDefinition? = null): T = get(named("test"), parameters) /** * Will register [definition] with [org.koin.core.module.Module.single] and key "test" */ -public inline fun Module.singleTest(createdAtStart: Boolean = false, noinline - definition: Definition): KoinDefinition = single(named("test"), createdAtStart = - createdAtStart, definition = definition) +public inline fun Module.singleTest(createdAtStart: Boolean = false, noinline definition: Definition): KoinDefinition = single(named("test"), createdAtStart = createdAtStart, definition = definition) /** * Will register [definition] with [org.koin.core.module.Module.factory] and key "test" */ -public inline fun Module.factoryTest(noinline definition: Definition): - KoinDefinition = factory(named("test"), definition = definition) +public inline fun Module.factoryTest(noinline definition: Definition): KoinDefinition = factory(named("test"), definition = definition) /** * @return Definition by key "testNullable" with [parameters] */ -public inline fun Scope.testNullable(noinline parameters: ParametersDefinition? = - null): T? = getOrNull(named("testNullable"), parameters) +public inline fun Scope.testNullable(noinline parameters: ParametersDefinition? = null): T? = getOrNull(named("testNullable"), parameters) /** * @return Definition by key "testNullable" with [parameters] */ -public inline fun Koin.testNullable(noinline parameters: ParametersDefinition? = - null): T? = getOrNull(named("testNullable"), parameters) +public inline fun Koin.testNullable(noinline parameters: ParametersDefinition? = null): T? = getOrNull(named("testNullable"), parameters) /** * Will register [definition] with [org.koin.core.module.Module.single] and key "testNullable" */ -public inline fun Module.singleTestNullable(createdAtStart: Boolean = false, - noinline definition: Definition): KoinDefinition = single(named("testNullable"), - createdAtStart = createdAtStart, definition = definition) +public inline fun Module.singleTestNullable(createdAtStart: Boolean = false, noinline definition: Definition): KoinDefinition = single(named("testNullable"), createdAtStart = createdAtStart, definition = definition) /** * Will register [definition] with [org.koin.core.module.Module.factory] and key "testNullable" */ -public inline fun Module.factoryTestNullable(noinline definition: Definition): - KoinDefinition = factory(named("testNullable"), definition = definition) +public inline fun Module.factoryTestNullable(noinline definition: Definition): KoinDefinition = factory(named("testNullable"), definition = definition) diff --git a/ksp/generator/src/main/kotlin/KClassTypeName.kt b/ksp/generator/src/main/kotlin/KClassTypeName.kt new file mode 100644 index 00000000000..dc35b0e53a7 --- /dev/null +++ b/ksp/generator/src/main/kotlin/KClassTypeName.kt @@ -0,0 +1,23 @@ +package dev.inmo.micro_ksp.generator + +import com.google.devtools.ksp.KSTypeNotPresentException +import com.google.devtools.ksp.KspExperimental +import com.squareup.kotlinpoet.ClassName +import com.squareup.kotlinpoet.asTypeName +import kotlin.reflect.KClass + +@Suppress("NOTHING_TO_INLINE") +@OptIn(KspExperimental::class) +inline fun safeClassName(classnameGetter: () -> KClass<*>) = runCatching { + classnameGetter().asTypeName() +}.getOrElse { e -> + if (e is KSTypeNotPresentException) { + ClassName( + e.ksType.declaration.packageName.asString(), + e.ksType.declaration.qualifiedName ?.asString() ?.replaceFirst(e.ksType.declaration.packageName.asString(), "") + ?: e.ksType.declaration.simpleName.asString() + ) + } else { + throw e + } +}