Skip to content

Commit

Permalink
Update to Kotlin 2.0.20 (#641)
Browse files Browse the repository at this point in the history
  • Loading branch information
Foso authored Aug 23, 2024
1 parent e0d126e commit 6eef948
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 48 deletions.
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 9 additions & 1 deletion docs/development.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# Development
# 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
6 changes: 3 additions & 3 deletions example/MultiplatformExample/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
repositories {
//mavenLocal()
// mavenLocal()
gradlePluginPortal()
google()
mavenCentral()
Expand All @@ -9,15 +9,15 @@ 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")
}
}

allprojects {
repositories {
//mavenLocal()
// mavenLocal()
google()
mavenCentral()
maven {
Expand Down
14 changes: 6 additions & 8 deletions example/MultiplatformExample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -82,10 +82,8 @@ android {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

}


tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
Expand All @@ -99,4 +97,4 @@ allprojects {
url = uri("https://oss.sonatype.org/content/repositories/snapshots/")
}
}
}
}
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -42,10 +44,15 @@ internal class CreateFuncTransformer(
// Find exampleKtorfit.create<TestApi>()
(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
}

Expand All @@ -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
Expand Down Expand Up @@ -98,7 +107,9 @@ internal class CreateFuncTransformer(
// Set _ExampleApiProvider() as argument for create<ExampleApi>()
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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -13,9 +14,10 @@ fun getCompilation(
kspArgs: MutableMap<String, String> = 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
}

0 comments on commit 6eef948

Please sign in to comment.