Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Kotlin 2.0 #51

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ open class LibraryKmpPlugin : Plugin<Project> {
private fun Project.enableExpectActualClasses() {
kotlin.targets.configureEach { target ->
target.compilations.configureEach { compilation ->
compilation.compilerOptions.options.freeCompilerArgs.add("-Xexpect-actual-classes")
compilation.compileTaskProvider.configure { task ->
task.compilerOptions.freeCompilerArgs.add("-Xexpect-actual-classes")
}
}
}
}
Expand Down Expand Up @@ -93,24 +95,21 @@ open class LibraryKmpPlugin : Plugin<Project> {
uniqueModuleName?.let { moduleName ->
kotlin.targets.configureEach { target ->
target.compilations.configureEach { compilation ->
compilation
.compilerOptions
.options
.let {
when (it) {
is KotlinNativeCompilerOptions -> {
it.moduleName.set(moduleName)
}

is KotlinJvmCompilerOptions -> {
it.moduleName.set(moduleName)
}

is KotlinJsCompilerOptions -> {
it.moduleName.set(moduleName)
}
compilation.compileTaskProvider.configure {
when (val compilerOptions = it.compilerOptions) {
is KotlinNativeCompilerOptions -> {
compilerOptions.moduleName.set(moduleName)
}

is KotlinJvmCompilerOptions -> {
compilerOptions.moduleName.set(moduleName)
}

is KotlinJsCompilerOptions -> {
compilerOptions.moduleName.set(moduleName)
}
}
}
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@ dependencies {
testRuntimeOnly libs.junit.jupiter.launcher

// Added so that the SymbolProcessor is picked up in tests.
testImplementation(libs.kotlin.inject.ksp.bugfix) {
// TODO: Remove this when upgrading to Kotlin 2.0
exclude group: 'com.google.devtools.ksp', module: 'symbol-processing-api'
}
testImplementation libs.kotlin.inject.ksp

// Bump transitive dependency.
// TODO: Enable with KSP2 and Kotlin 2.0 again.
// testImplementation libs.ksp
testImplementation libs.ksp
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ import com.tschuchort.compiletesting.JvmCompilationResult
import com.tschuchort.compiletesting.KotlinCompilation
import com.tschuchort.compiletesting.SourceFile
import com.tschuchort.compiletesting.addPreviousResultToClasspath
import com.tschuchort.compiletesting.kspArgs
import com.tschuchort.compiletesting.kspIncremental
import com.tschuchort.compiletesting.kspWithCompilation
import com.tschuchort.compiletesting.symbolProcessorProviders
import com.tschuchort.compiletesting.configureKsp
import org.intellij.lang.annotations.Language
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
import org.jetbrains.kotlin.config.JvmTarget
Expand Down Expand Up @@ -44,16 +41,25 @@ class Compilation internal constructor(
processorsConfigured = true

with(kotlinCompilation) {
this.symbolProcessorProviders += ServiceLoader.load(
SymbolProcessorProvider::class.java,
SymbolProcessorProvider::class.java.classLoader,
)
this.symbolProcessorProviders += symbolProcessorProviders
this.kspArgs.putAll(processorOptions)
val useKsp2 = false

if (!useKsp2) {
languageVersion = "1.9"
}

// Run KSP embedded directly within this kotlinc invocation
kspWithCompilation = true
kspIncremental = true
configureKsp(useKsp2 = useKsp2) {
this.symbolProcessorProviders += ServiceLoader.load(
SymbolProcessorProvider::class.java,
SymbolProcessorProvider::class.java.classLoader,
)

this.symbolProcessorProviders += symbolProcessorProviders
this.processorOptions.putAll(processorOptions)

// Run KSP embedded directly within this kotlinc invocation
this.withCompilation = true
this.incremental = true
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ class MergeScopeParserTest {
symbolProcessorProviders = setOf(symbolProcessorProvider(block)),
)
.compile(*sources) {
assertThat(this.exitCode).isEqualTo(exitCode)
if (exitCode == OK) {
assertThat(exitCode).isOk()
} else {
assertThat(exitCode).isError()
}
}
}

Expand Down
22 changes: 9 additions & 13 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
[versions]
agp = "8.2.2"
agp = "8.5.2"
android-compileSdk = "34"
android-minSdk = "21"
assertk = "0.28.1"
auto-service = "1.1.1"
auto-service-ksp = "1.2.0"
detekt = "1.23.6"
junit-jupiter = "5.10.3"
kotlin = "1.9.24"
kotlin-compile-testing = "0.4.1"
detekt = "1.23.7"
junit-jupiter = "5.11.0"
kotlin = "2.0.21"
kotlin-compile-testing = "0.5.1"
kotlin-hierarchy = "1.1"
kotlin-inject = "0.7.1"
# This is a build with the latest fixes. We need that in the sample app. 0.7.2 depends on
# Kotlin 2.0, and we can't do the upgrade yet.
kotlin-inject-bugfix = "0.7.2"
kotlin-poet = "1.17.0"
kotlinx-binaryCompatibilityValidator = "0.16.2"
ksp = "1.9.24-1.0.20"
kotlin-inject = "0.7.2"
kotlin-poet = "1.18.1"
kotlinx-binaryCompatibilityValidator = "0.16.3"
ksp = "2.0.21-1.0.25"
ktlint-binary = "1.2.1"
ktlint-gradle = "12.1.1"
maven-publish = "0.29.0"
Expand All @@ -38,7 +35,6 @@ kotlin-gradle-plugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", v
kotlin-gradle-plugin-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }
kotlin-hierarchy-plugin = { module = "io.github.terrakok:kmp-hierarchy", version.ref = "kotlin-hierarchy" }
kotlin-inject-ksp = { module = "me.tatarka.inject:kotlin-inject-compiler-ksp", version.ref = "kotlin-inject" }
kotlin-inject-ksp-bugfix = { module = "me.tatarka.inject:kotlin-inject-compiler-ksp", version.ref = "kotlin-inject-bugfix" }
kotlin-inject-runtime = { module = "me.tatarka.inject:kotlin-inject-runtime", version.ref = "kotlin-inject" }
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
kotlinx-binaryCompatibilityValidator = { module = "org.jetbrains.kotlinx:binary-compatibility-validator", version.ref = "kotlinx-binaryCompatibilityValidator" }
Expand Down
Loading