mirror of
https://github.com/fankes/moshi.git
synced 2025-10-18 23:49:21 +08:00
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:
@@ -2,6 +2,7 @@ import com.diffplug.gradle.spotless.JavaExtension
|
||||
import com.vanniktech.maven.publish.MavenPublishBaseExtension
|
||||
import com.vanniktech.maven.publish.SonatypeHost
|
||||
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.tasks.KotlinCompile
|
||||
import java.net.URL
|
||||
@@ -84,11 +85,9 @@ subprojects {
|
||||
|
||||
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
// TODO re-enable when no longer supporting multiple kotlin versions
|
||||
// @Suppress("SuspiciousCollectionReassignment")
|
||||
// freeCompilerArgs += listOf("-progressive")
|
||||
jvmTarget = libs.versions.jvmTarget.get()
|
||||
compilerOptions {
|
||||
freeCompilerArgs.add("-progressive")
|
||||
jvmTarget.set(JvmTarget.fromTarget(libs.versions.jvmTarget.get()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -13,8 +13,8 @@ dependencies {
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
freeCompilerArgs += listOf(
|
||||
compilerOptions {
|
||||
freeCompilerArgs.add(
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi",
|
||||
)
|
||||
}
|
||||
|
@@ -2,14 +2,14 @@
|
||||
autoService = "1.0.1"
|
||||
gjf = "1.15.0"
|
||||
jvmTarget = "1.8"
|
||||
kotlin = "1.7.0"
|
||||
kotlinCompileTesting = "1.4.9"
|
||||
kotlinpoet = "1.12.0"
|
||||
ksp = "1.7.0-1.0.6"
|
||||
kotlin = "1.8.21"
|
||||
kotlinCompileTesting = "0.2.1"
|
||||
kotlinpoet = "1.13.2"
|
||||
ksp = "1.8.21-1.0.11"
|
||||
ktlint = "0.48.2"
|
||||
|
||||
[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" }
|
||||
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
|
||||
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-metadata = { module = "com.squareup:kotlinpoet-metadata", 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-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
|
||||
okio = "com.squareup.okio:okio:3.3.0"
|
||||
@@ -37,6 +37,6 @@ okio = "com.squareup.okio:okio:3.3.0"
|
||||
# Test libs
|
||||
assertj = "org.assertj:assertj-core:3.24.2"
|
||||
junit = "junit:junit:4.13.2"
|
||||
kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" }
|
||||
kotlinCompileTesting-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref ="kotlinCompileTesting" }
|
||||
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
|
||||
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
|
||||
truth = "com.google.truth:truth:1.1.3"
|
||||
|
@@ -13,15 +13,20 @@ plugins {
|
||||
}
|
||||
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
@Suppress("SuspiciousCollectionReassignment")
|
||||
freeCompilerArgs += listOf(
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll(
|
||||
"-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
|
||||
"-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
|
||||
tasks.withType<Test>().configureEach {
|
||||
jvmArgs(
|
||||
|
@@ -262,8 +262,12 @@ public class AdapterGenerator(
|
||||
|
||||
val typeRenderer: TypeRenderer = object : TypeRenderer() {
|
||||
override fun renderTypeVariable(typeVariable: TypeVariableName): CodeBlock {
|
||||
val index = typeVariables.indexOfFirst { it == typeVariable }
|
||||
check(index != -1) { "Unexpected type variable $typeVariable" }
|
||||
// Match only by name because equality checks for more things than just the name. For example, a base class
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
@@ -618,7 +622,10 @@ public class AdapterGenerator(
|
||||
|
||||
if (useDefaultsConstructor) {
|
||||
// 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")
|
||||
|
@@ -34,14 +34,10 @@ tasks.withType<Test>().configureEach {
|
||||
jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
|
||||
}
|
||||
|
||||
val useWError = findProperty("kotlinLanguageVersion")?.toString()
|
||||
?.startsWith("1.5")
|
||||
?: false
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
allWarningsAsErrors = useWError
|
||||
@Suppress("SuspiciousCollectionReassignment")
|
||||
freeCompilerArgs += listOf(
|
||||
compilerOptions {
|
||||
allWarningsAsErrors.set(true)
|
||||
freeCompilerArgs.add(
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi",
|
||||
)
|
||||
}
|
||||
|
@@ -35,14 +35,10 @@ tasks.withType<Test>().configureEach {
|
||||
jvmArgs("--add-opens=java.base/java.io=ALL-UNNAMED")
|
||||
}
|
||||
|
||||
val useWError = findProperty("kotlinLanguageVersion")?.toString()
|
||||
?.startsWith("1.5")
|
||||
?: false
|
||||
tasks.withType<KotlinCompile>().configureEach {
|
||||
kotlinOptions {
|
||||
allWarningsAsErrors = useWError
|
||||
@Suppress("SuspiciousCollectionReassignment")
|
||||
freeCompilerArgs += listOf(
|
||||
compilerOptions {
|
||||
allWarningsAsErrors.set(true)
|
||||
freeCompilerArgs.add(
|
||||
"-opt-in=kotlin.ExperimentalStdlibApi",
|
||||
)
|
||||
}
|
||||
|
@@ -1083,6 +1083,7 @@ class KotlinJsonAdapterTest {
|
||||
val moshi = Moshi.Builder().add(KotlinJsonAdapterFactory()).build()
|
||||
val adapter = moshi.adapter(type)
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
Assertions.assertThat(adapter.fromJson(json)).isEqualToComparingFieldByFieldRecursively(value)
|
||||
assertThat(adapter.toJson(value)).isEqualTo(json)
|
||||
}
|
||||
|
@@ -2,6 +2,7 @@ import com.vanniktech.maven.publish.JavadocJar.Dokka
|
||||
import com.vanniktech.maven.publish.KotlinJvm
|
||||
import com.vanniktech.maven.publish.MavenPublishBaseExtension
|
||||
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.tasks.KotlinCompile
|
||||
|
||||
@@ -24,9 +25,13 @@ val customLauncher = service.launcherFor {
|
||||
languageVersion.set(JavaLanguageVersion.of(17))
|
||||
}
|
||||
|
||||
tasks.named<JavaCompile>("compileJava16Java") {
|
||||
options.release.set(16)
|
||||
}
|
||||
|
||||
tasks.named<KotlinCompile>("compileJava16Kotlin") {
|
||||
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
|
||||
@@ -59,16 +64,14 @@ tasks.withType<Test>().configureEach {
|
||||
|
||||
tasks.withType<KotlinCompile>()
|
||||
.configureEach {
|
||||
kotlinOptions {
|
||||
val toAdd = mutableListOf(
|
||||
compilerOptions {
|
||||
freeCompilerArgs.addAll(
|
||||
"-opt-in=kotlin.contracts.ExperimentalContracts",
|
||||
"-Xjvm-default=all",
|
||||
)
|
||||
if (name.contains("test", true)) {
|
||||
toAdd += "-opt-in=kotlin.ExperimentalStdlibApi"
|
||||
freeCompilerArgs.add("-opt-in=kotlin.ExperimentalStdlibApi")
|
||||
}
|
||||
@Suppress("SuspiciousCollectionReassignment") // It's not suspicious
|
||||
freeCompilerArgs += toAdd
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user