From 6eef948be1229ff5887c787eec837dff0e2f231a Mon Sep 17 00:00:00 2001 From: Jens Klingenberg Date: Fri, 23 Aug 2024 17:45:51 +0200 Subject: [PATCH] Update to Kotlin 2.0.20 (#641) --- docs/CHANGELOG.md | 3 ++- docs/development.md | 10 ++++++- example/MultiplatformExample/build.gradle.kts | 6 ++--- .../shared/build.gradle.kts | 14 +++++----- gradle/libs.versions.toml | 8 +++--- .../ktorfit/CreateFuncTransformer.kt | 23 +++++++++++----- .../ktorfit/ReqBuilderAnnotationsTest.kt | 26 +++---------------- .../de/jensklingenberg/ktorfit/Utils.kt | 6 +++-- 8 files changed, 48 insertions(+), 48 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 049464e0e..8e0dae059 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -25,7 +25,8 @@ But there is no intent to bump the Ktorfit major version for every KSP update. - Kotlin 2.0.10: 2.0.1-2.0.10 - 2024-08-10 - Kotlin 2.0.20-RC: 2.0.1-2.0.20-RC - 2024-08-13 - Kotlin 2.0.20-RC2: 2.0.1-2.0.20-RC2 - 2024-08-13 - +- Kotlin 2.0.20: 2.0.1-2.0.20 - 2024-08-23 + ### ktorfit-ksp - KSP 1.0.24: ktorfit-ksp-2.0.1-1.0.24 - 2024-08-08 diff --git a/docs/development.md b/docs/development.md index 90c64e52f..70fe44ec0 100644 --- a/docs/development.md +++ b/docs/development.md @@ -1 +1,9 @@ -# Development \ No newline at end of file +# Development + +# Update Ktorfit for new Kotlin version +- Bump **kotlin** in libs.versions +- Change **ktorfitCompiler** in libs.versions to KTORFIT_VERSION-NEW_KOTLIN_VERSION +- Run tests in :ktorfit-compiler-plugin +- Create a PR against master +- Merge PR +- Run GitHub Actions "publish" workflow \ No newline at end of file diff --git a/example/MultiplatformExample/build.gradle.kts b/example/MultiplatformExample/build.gradle.kts index f071dc823..46058a423 100644 --- a/example/MultiplatformExample/build.gradle.kts +++ b/example/MultiplatformExample/build.gradle.kts @@ -1,6 +1,6 @@ buildscript { repositories { - //mavenLocal() + // mavenLocal() gradlePluginPortal() google() mavenCentral() @@ -9,7 +9,7 @@ buildscript { } } dependencies { - classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.0") + classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.0.20") classpath("com.android.tools.build:gradle:7.3.1") classpath("org.jetbrains.kotlin:kotlin-serialization:2.0.0") } @@ -17,7 +17,7 @@ buildscript { allprojects { repositories { - //mavenLocal() + // mavenLocal() google() mavenCentral() maven { diff --git a/example/MultiplatformExample/shared/build.gradle.kts b/example/MultiplatformExample/shared/build.gradle.kts index 2d8550ed0..c36a5f5e7 100644 --- a/example/MultiplatformExample/shared/build.gradle.kts +++ b/example/MultiplatformExample/shared/build.gradle.kts @@ -4,9 +4,9 @@ plugins { kotlin("multiplatform") kotlin("native.cocoapods") id("com.android.library") - id("com.google.devtools.ksp") version "2.0.0-1.0.22" + id("com.google.devtools.ksp") version "2.0.20-1.0.24" id("kotlinx-serialization") - id("de.jensklingenberg.ktorfit") version "2.0.0" + id("de.jensklingenberg.ktorfit") version "2.0.1" } ktorfit { @@ -16,7 +16,7 @@ ktorfit { version = "1.0" val ktorVersion = "2.3.11" -val ktorfitVersion = "2.0.0" +val ktorfitVersion = "2.0.1" kotlin { jvmToolchain(8) @@ -46,13 +46,13 @@ kotlin { val commonMain by getting { dependencies { implementation("de.jensklingenberg.ktorfit:ktorfit-lib:$ktorfitVersion") - //implementation("de.jensklingenberg.ktorfit:ktorfit-lib-light:$ktorfitVersion") + // implementation("de.jensklingenberg.ktorfit:ktorfit-lib-light:$ktorfitVersion") implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.8.1") implementation("de.jensklingenberg.ktorfit:ktorfit-converters-response:$ktorfitVersion") implementation("de.jensklingenberg.ktorfit:ktorfit-converters-call:$ktorfitVersion") implementation("de.jensklingenberg.ktorfit:ktorfit-converters-flow:$ktorfitVersion") - //Only needed when you want to use Kotlin Serialization + // Only needed when you want to use Kotlin Serialization implementation("io.ktor:ktor-client-serialization:$ktorVersion") implementation("io.ktor:ktor-client-content-negotiation:$ktorVersion") implementation("io.ktor:ktor-serialization-kotlinx-json:$ktorVersion") @@ -82,10 +82,8 @@ android { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 } - } - tasks.withType { kotlinOptions { jvmTarget = "1.8" @@ -99,4 +97,4 @@ allprojects { url = uri("https://oss.sonatype.org/content/repositories/snapshots/") } } -} \ No newline at end of file +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5aa556d14..cbda8a502 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -5,15 +5,15 @@ binaryCompatibilityValidator = "0.14.0" coroutines = "1.8.1" detekt = "1.23.6" junit = "4.13.2" -kctfork = "0.4.1" -kotlin = "2.0.10" +kctfork = "0.5.1" +kotlin = "2.0.20" kotlinPoet = "1.18.1" -kspVersion = "2.0.10-1.0.24" +kspVersion = "2.0.20-1.0.24" groupId = "de.jensklingenberg.ktorfit" ktorfit = "2.0.1" ktorfitKsp = "2.0.1-1.0.24" -ktorfitCompiler = "2.0.1-2.0.10" +ktorfitCompiler = "2.0.1-2.0.20" ktorfitCallConverter = "2.0.1" ktorfitFlowConverter = "2.0.1" ktorfitResponseConverter = "2.0.1" diff --git a/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt b/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt index 0d0ed6aed..5f2f4764a 100644 --- a/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt +++ b/ktorfit-compiler-plugin/src/main/java/de/jensklingenberg/ktorfit/CreateFuncTransformer.kt @@ -2,15 +2,17 @@ package de.jensklingenberg.ktorfit import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.ir.descriptors.toIrBasedKotlinType import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.types.classFqName import org.jetbrains.kotlin.ir.types.defaultType -import org.jetbrains.kotlin.ir.types.impl.originalKotlinType import org.jetbrains.kotlin.ir.util.constructors +import org.jetbrains.kotlin.ir.util.dumpKotlinLike import org.jetbrains.kotlin.ir.util.isInterface +import org.jetbrains.kotlin.js.descriptorUtils.getKotlinTypeFqName import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -42,10 +44,15 @@ internal class CreateFuncTransformer( // Find exampleKtorfit.create() (expression as? IrCall)?.let { irCall -> if (irCall.typeArgumentsCount > 0) { - if (!expression.symbol.owner.symbol.toString().contains(KTORFIT_PACKAGE)) { + if (!expression.symbol.owner.symbol + .toString() + .contains(KTORFIT_PACKAGE) + ) { return expression } - if (expression.symbol.owner.name.asString() != KTORFIT_CREATE) { + if (expression.symbol.owner.name + .asString() != KTORFIT_CREATE + ) { return expression } @@ -59,12 +66,14 @@ internal class CreateFuncTransformer( if (!argumentType.isInterface()) { throw IllegalStateException( - errorTypeArgumentNotInterface(argumentType.originalKotlinType.toString()), + errorTypeArgumentNotInterface(argumentType.dumpKotlinLike()), ) } if (classFqName == null) { - throw IllegalStateException(errorClassNotFound(argumentType.originalKotlinType.toString())) + throw IllegalStateException( + errorClassNotFound(argumentType.toIrBasedKotlinType().getKotlinTypeFqName(false)) + ) } val packageName = classFqName.packageName @@ -98,7 +107,9 @@ internal class CreateFuncTransformer( // Set _ExampleApiProvider() as argument for create() irCall.putValueArgument(0, newCall) debugLogger.log( - "Transformed " + argumentType.originalKotlinType.toString() + " to _$className" + "Provider", + "Transformed " + argumentType.toIrBasedKotlinType().getKotlinTypeFqName(false).substringAfterLast(".") + + " to _$className" + + "Provider", ) return super.visitExpression(irCall) } diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReqBuilderAnnotationsTest.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReqBuilderAnnotationsTest.kt index a9226cd96..e916cb696 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReqBuilderAnnotationsTest.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/ReqBuilderAnnotationsTest.kt @@ -2,9 +2,7 @@ package de.jensklingenberg.ktorfit import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile -import com.tschuchort.compiletesting.kspIncremental import com.tschuchort.compiletesting.kspSourcesDir -import com.tschuchort.compiletesting.symbolProcessorProviders import de.jensklingenberg.ktorfit.model.KtorfitError import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse @@ -79,13 +77,7 @@ interface TestService { val expectedRequestBuilderArgumentText = "builder(this)" - val compilation = - KotlinCompilation().apply { - sources = listOf(httpReqBuilderSource, source) - inheritClassPath = true - symbolProcessorProviders = listOf(KtorfitProcessorProvider()) - kspIncremental = true - } + val compilation = getCompilation(listOf(httpReqBuilderSource, source)) val result = compilation.compile() assertEquals(KotlinCompilation.ExitCode.OK, result.exitCode) @@ -120,13 +112,7 @@ interface TestService { """, ) - val compilation = - KotlinCompilation().apply { - sources = listOf(httpReqBuilderSource, source) - inheritClassPath = true - symbolProcessorProviders = listOf(KtorfitProcessorProvider()) - kspIncremental = true - } + val compilation = getCompilation(listOf(httpReqBuilderSource, source)) val result = compilation.compile() assertEquals(KotlinCompilation.ExitCode.COMPILATION_ERROR, result.exitCode) @@ -153,13 +139,7 @@ interface TestService { """, ) - val compilation = - KotlinCompilation().apply { - sources = listOf(httpReqBuilderSource, source) - inheritClassPath = true - symbolProcessorProviders = listOf(KtorfitProcessorProvider()) - kspIncremental = true - } + val compilation = getCompilation(listOf(httpReqBuilderSource, source)) val result = compilation.compile() assertEquals(KotlinCompilation.ExitCode.COMPILATION_ERROR, result.exitCode) diff --git a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/Utils.kt b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/Utils.kt index 5d339e688..4e6848c6b 100644 --- a/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/Utils.kt +++ b/ktorfit-ksp/src/test/kotlin/de/jensklingenberg/ktorfit/Utils.kt @@ -4,6 +4,7 @@ import com.tschuchort.compiletesting.KotlinCompilation import com.tschuchort.compiletesting.SourceFile import com.tschuchort.compiletesting.kspArgs import com.tschuchort.compiletesting.kspIncremental +import com.tschuchort.compiletesting.kspProcessorOptions import com.tschuchort.compiletesting.symbolProcessorProviders import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi @@ -13,9 +14,10 @@ fun getCompilation( kspArgs: MutableMap = mutableMapOf(), ): KotlinCompilation = KotlinCompilation().apply { + languageVersion = "1.9" this.sources = sources inheritClassPath = true - symbolProcessorProviders = listOf(KtorfitProcessorProvider()) + symbolProcessorProviders = mutableListOf(KtorfitProcessorProvider()) kspIncremental = true - this.kspArgs = kspArgs + this.kspProcessorOptions = kspArgs }