Update kotlin monorepo (#1614)

* Update kotlin monorepo

* Update ksp to v1.8.0-1.0.9

* Lower metadata to 0.5.0

* Update KCT

* Update to compilerOptions

* Suppress deprecation

* Add missing java target too

* Raise it again because it's broken on all

* Kotlin 1.8.20 + updated kotlinpoet

* Update kotlinpoet

* Update kotlin

* Fix KSP equality check for KotlinPoet 1.13.x

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <github@jakewharton.com>
Co-authored-by: Zac Sweers <pandanomic@gmail.com>
This commit is contained in:
renovate[bot]
2023-05-05 18:04:57 -04:00
committed by GitHub
parent bf4b83d1dc
commit c11f0e168c
9 changed files with 48 additions and 41 deletions

View File

@@ -2,6 +2,7 @@ import com.diffplug.gradle.spotless.JavaExtension
import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.MavenPublishBaseExtension
import com.vanniktech.maven.publish.SonatypeHost import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.net.URL import java.net.URL
@@ -84,11 +85,9 @@ subprojects {
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") { pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
kotlinOptions { compilerOptions {
// TODO re-enable when no longer supporting multiple kotlin versions freeCompilerArgs.add("-progressive")
// @Suppress("SuspiciousCollectionReassignment") jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
// freeCompilerArgs += listOf("-progressive")
jvmTarget = libs.versions.jvmTarget.get()
} }
} }

View File

@@ -13,8 +13,8 @@ dependencies {
} }
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
kotlinOptions { compilerOptions {
freeCompilerArgs += listOf( freeCompilerArgs.add(
"-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlin.ExperimentalStdlibApi",
) )
} }

View File

@@ -2,14 +2,14 @@
autoService = "1.0.1" autoService = "1.0.1"
gjf = "1.15.0" gjf = "1.15.0"
jvmTarget = "1.8" jvmTarget = "1.8"
kotlin = "1.7.0" kotlin = "1.8.21"
kotlinCompileTesting = "1.4.9" kotlinCompileTesting = "0.2.1"
kotlinpoet = "1.12.0" kotlinpoet = "1.13.2"
ksp = "1.7.0-1.0.6" ksp = "1.8.21-1.0.11"
ktlint = "0.48.2" ktlint = "0.48.2"
[plugins] [plugins]
dokka = { id = "org.jetbrains.dokka", version = "1.7.20" } dokka = { id = "org.jetbrains.dokka", version = "1.8.10" }
japicmp = { id = "me.champeau.gradle.japicmp", version = "0.4.1" } japicmp = { id = "me.champeau.gradle.japicmp", version = "0.4.1" }
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.2" } mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.25.2" }
@@ -29,7 +29,7 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref =
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
kotlinpoet-metadata = { module = "com.squareup:kotlinpoet-metadata", version.ref = "kotlinpoet" } kotlinpoet-metadata = { module = "com.squareup:kotlinpoet-metadata", version.ref = "kotlinpoet" }
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" } kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }
kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.4.2" kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0"
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" } ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
okio = "com.squareup.okio:okio:3.3.0" okio = "com.squareup.okio:okio:3.3.0"
@@ -37,6 +37,6 @@ okio = "com.squareup.okio:okio:3.3.0"
# Test libs # Test libs
assertj = "org.assertj:assertj-core:3.24.2" assertj = "org.assertj:assertj-core:3.24.2"
junit = "junit:junit:4.13.2" junit = "junit:junit:4.13.2"
kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" } kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
kotlinCompileTesting-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref ="kotlinCompileTesting" } kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
truth = "com.google.truth:truth:1.1.3" truth = "com.google.truth:truth:1.1.3"

View File

@@ -13,15 +13,20 @@ plugins {
} }
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
kotlinOptions { compilerOptions {
@Suppress("SuspiciousCollectionReassignment") freeCompilerArgs.addAll(
freeCompilerArgs += listOf(
"-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview", "-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
"-opt-in=com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi", "-opt-in=com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi",
) )
} }
} }
tasks.compileTestKotlin {
compilerOptions {
freeCompilerArgs.add("-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi")
}
}
// --add-opens for kapt to work. KGP covers this for us but local JVMs in tests do not // --add-opens for kapt to work. KGP covers this for us but local JVMs in tests do not
tasks.withType<Test>().configureEach { tasks.withType<Test>().configureEach {
jvmArgs( jvmArgs(

View File

@@ -262,8 +262,12 @@ public class AdapterGenerator(
val typeRenderer: TypeRenderer = object : TypeRenderer() { val typeRenderer: TypeRenderer = object : TypeRenderer() {
override fun renderTypeVariable(typeVariable: TypeVariableName): CodeBlock { override fun renderTypeVariable(typeVariable: TypeVariableName): CodeBlock {
val index = typeVariables.indexOfFirst { it == typeVariable } // Match only by name because equality checks for more things than just the name. For example, a base class
check(index != -1) { "Unexpected type variable $typeVariable" } // may declare "T" but the subclass declares "T : Number", which is legal but will fail an equals() test.
val index = typeVariables.indexOfFirst { it.name == typeVariable.name }
check(index != -1) {
"Unexpected type variable $typeVariable"
}
return CodeBlock.of("%N[%L]", typesParam, index) return CodeBlock.of("%N[%L]", typesParam, index)
} }
} }
@@ -618,7 +622,10 @@ public class AdapterGenerator(
if (useDefaultsConstructor) { if (useDefaultsConstructor) {
// Add the masks and a null instance for the trailing default marker instance // Add the masks and a null instance for the trailing default marker instance
result.addCode(",\n%L,\n/*·DefaultConstructorMarker·*/·null", maskNames.map { CodeBlock.of("%L", it) }.joinToCode(", ")) result.addCode(
",\n%L,\n/*·DefaultConstructorMarker·*/·null",
maskNames.map { CodeBlock.of("%L", it) }.joinToCode(", "),
)
} }
result.addCode("\n»)\n") result.addCode("\n»)\n")

View File

@@ -34,14 +34,10 @@ tasks.withType<Test>().configureEach {
jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED") jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
} }
val useWError = findProperty("kotlinLanguageVersion")?.toString()
?.startsWith("1.5")
?: false
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
kotlinOptions { compilerOptions {
allWarningsAsErrors = useWError allWarningsAsErrors.set(true)
@Suppress("SuspiciousCollectionReassignment") freeCompilerArgs.add(
freeCompilerArgs += listOf(
"-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlin.ExperimentalStdlibApi",
) )
} }

View File

@@ -35,14 +35,10 @@ tasks.withType<Test>().configureEach {
jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED") jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
} }
val useWError = findProperty("kotlinLanguageVersion")?.toString()
?.startsWith("1.5")
?: false
tasks.withType<KotlinCompile>().configureEach { tasks.withType<KotlinCompile>().configureEach {
kotlinOptions { compilerOptions {
allWarningsAsErrors = useWError allWarningsAsErrors.set(true)
@Suppress("SuspiciousCollectionReassignment") freeCompilerArgs.add(
freeCompilerArgs += listOf(
"-opt-in=kotlin.ExperimentalStdlibApi", "-opt-in=kotlin.ExperimentalStdlibApi",
) )
} }

View File

@@ -1083,6 +1083,7 @@ class KotlinJsonAdapterTest {
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build() val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
val adapter = moshi.adapter(type) val adapter = moshi.adapter(type)
@Suppress("DEPRECATION")
Assertions.assertThat(adapter.fromJson(json)).isEqualToComparingFieldByFieldRecursively(value) Assertions.assertThat(adapter.fromJson(json)).isEqualToComparingFieldByFieldRecursively(value)
assertThat(adapter.toJson(value)).isEqualTo(json) assertThat(adapter.toJson(value)).isEqualTo(json)
} }

View File

@@ -2,6 +2,7 @@ import com.vanniktech.maven.publish.JavadocJar.Dokka
import com.vanniktech.maven.publish.KotlinJvm import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.MavenPublishBaseExtension import com.vanniktech.maven.publish.MavenPublishBaseExtension
import org.gradle.jvm.tasks.Jar import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation import org.jetbrains.kotlin.gradle.plugin.KotlinCompilation
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
@@ -24,9 +25,13 @@ val customLauncher = service.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17)) languageVersion.set(JavaLanguageVersion.of(17))
} }
tasks.named<JavaCompile>("compileJava16Java") {
options.release.set(16)
}
tasks.named<KotlinCompile>("compileJava16Kotlin") { tasks.named<KotlinCompile>("compileJava16Kotlin") {
kotlinJavaToolchain.toolchain.use(customLauncher) kotlinJavaToolchain.toolchain.use(customLauncher)
kotlinOptions.jvmTarget = "16" compilerOptions.jvmTarget.set(JvmTarget.JVM_16)
} }
// Grant our java16 sources access to internal APIs in the main source set // Grant our java16 sources access to internal APIs in the main source set
@@ -59,16 +64,14 @@ tasks.withType<Test>().configureEach {
tasks.withType<KotlinCompile>() tasks.withType<KotlinCompile>()
.configureEach { .configureEach {
kotlinOptions { compilerOptions {
val toAdd = mutableListOf( freeCompilerArgs.addAll(
"-opt-in=kotlin.contracts.ExperimentalContracts", "-opt-in=kotlin.contracts.ExperimentalContracts",
"-Xjvm-default=all", "-Xjvm-default=all",
) )
if (name.contains("test", true)) { if (name.contains("test", true)) {
toAdd += "-opt-in=kotlin.ExperimentalStdlibApi" freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi")
} }
@Suppress("SuspiciousCollectionReassignment") // It's not suspicious
freeCompilerArgs += toAdd
} }
} }