Update Kotlin to 2.0 (#900)

- update Kotlin from 1.7.10 to 2.0.21
  - Kotlin 1.6 dependencies in Gradle lock files are expected because kotlinc,
    which is also used by some tests, internally uses some 1.6 dependencies
    for backwards compatibility reasons.
- update kotlinx-html and kotlinx-serialization
- adapt Kotlin code where necessary
- use Kotlin stdlib Path APIs where possible
- fix IntelliJ Kotlin inspection warnings
- reformat code with `./gradlew spotlessApply`
  - ktfmt adds lots of trailing commas
- Add workaround to fix IntelliJ "unresolved reference" errors
This commit is contained in:
odenix
2025-01-23 14:41:59 -08:00
committed by GitHub
parent cdd6d52642
commit 258eda8630
87 changed files with 1042 additions and 1004 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,14 +17,14 @@ package org.pkl.gradle
import java.net.URI
import java.nio.file.Path
import kotlin.io.path.createParentDirectories
import kotlin.io.path.writeText
import org.assertj.core.api.Assertions.assertThat
import org.gradle.testkit.runner.BuildResult
import org.gradle.testkit.runner.GradleRunner
import org.gradle.testkit.runner.UnexpectedBuildFailure
import org.junit.jupiter.api.io.TempDir
import org.pkl.commons.createParentDirectories
import org.pkl.commons.readString
import org.pkl.commons.writeString
abstract class AbstractTest {
private val gradleVersion: String? = System.getProperty("testGradleVersion")
@@ -57,10 +57,10 @@ abstract class AbstractTest {
}
protected fun writeFile(fileName: String, contents: String): Path {
return testProjectDir
.resolve(fileName)
.apply { createParentDirectories() }
.writeString(contents.trimIndent())
return testProjectDir.resolve(fileName).apply {
createParentDirectories()
writeText(contents.trimIndent())
}
}
protected fun checkFileContents(file: Path, contents: String) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
val baseDir = testProjectDir.resolve("build/generated/java/foo/bar")
val moduleFile = baseDir.resolve("Mod.java")
assertThat(baseDir.listDirectoryEntries().count()).isEqualTo(1)
assertThat(baseDir.listDirectoryEntries().size).isEqualTo(1)
assertThat(moduleFile).exists()
val text = moduleFile.readText()
@@ -44,7 +44,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
"""
|public final class Mod {
| public final @Nonnull Object other;
"""
""",
)
checkTextContains(
@@ -54,7 +54,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
| public final @Nonnull String name;
|
| public final @Nonnull List<Address> addresses;
"""
""",
)
checkTextContains(
@@ -64,7 +64,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
| public final @Nonnull String street;
|
| public final long zip;
"""
""",
)
}
@@ -100,7 +100,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
}
}
}
"""
""",
)
val result = runTask("evalTest", true)
@@ -139,7 +139,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
}
}
}
"""
""",
)
}
@@ -160,7 +160,7 @@ class JavaCodeGeneratorsTest : AbstractTest() {
}
other = 42
"""
""",
)
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
val baseDir = testProjectDir.resolve("build/generated/kotlin/foo/bar")
val kotlinFile = baseDir.resolve("Mod.kt")
assertThat(baseDir.listDirectoryEntries().count()).isEqualTo(1)
assertThat(baseDir.listDirectoryEntries().size).isEqualTo(1)
assertThat(kotlinFile).exists()
val text = kotlinFile.readText()
@@ -39,11 +39,14 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
// shading must not affect generated code
assertThat(text).doesNotContain("org.pkl.thirdparty")
checkTextContains(text, """
checkTextContains(
text,
"""
|data class Mod(
| val other: Any?
|)
""")
""",
)
checkTextContains(
text,
@@ -52,7 +55,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
| val name: String,
| val addresses: List<Address>
| )
"""
""",
)
checkTextContains(
@@ -62,7 +65,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
| open val street: String,
| open val zip: Long
| )
"""
""",
)
}
@@ -97,7 +100,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
}
}
}
"""
""",
)
val result = runTask("evalTest", true)
@@ -148,7 +151,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
}
}
}
"""
""",
)
}
@@ -170,7 +173,7 @@ class KotlinCodeGeneratorsTest : AbstractTest() {
}
other = 42
"""
""",
)
}
}