Skip to content

Commit 8f951b0

Browse files
ZacSweerstrevjonezyogurtearl
authored
1.15.0 preperations (#1671)
* Update kotlin and gradle infrastructure * test case and possible fix for messaging when type resolution fails due to invalid syntax of a generic property (#1527) * Suppress warning in generated code (#1547) * Align versions * Deprecate kapt with a warning message --------- Co-authored-by: Trevor Jones <[email protected]> Co-authored-by: Michael Bailey <[email protected]>
1 parent a86a068 commit 8f951b0

File tree

7 files changed

+50
-12
lines changed

7 files changed

+50
-12
lines changed

gradle/libs.versions.toml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
autoService = "1.0"
1717
gjf = "1.11.0"
1818
jvmTarget = "1.8"
19-
kotlin = "1.7.0"
20-
kotlinCompileTesting = "1.4.9"
21-
kotlinpoet = "1.12.0"
22-
ksp = "1.7.0-1.0.6"
19+
kotlin = "1.8.21"
20+
kotlinCompileTesting = "0.2.1"
21+
kotlinpoet = "1.13.2"
22+
ksp = "1.8.21-1.0.11"
2323
ktlint = "0.41.0"
2424

2525
[plugins]
26-
dokka = { id = "org.jetbrains.dokka", version = "1.7.0" }
26+
dokka = { id = "org.jetbrains.dokka", version = "1.8.10" }
2727
japicmp = { id = "me.champeau.gradle.japicmp", version = "0.2.9" }
2828
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
2929
mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.21.0" }
@@ -37,19 +37,21 @@ autoService = { module = "com.google.auto.service:auto-service-annotations", ver
3737
autoService-ksp = "dev.zacsweers.autoservice:auto-service-ksp:1.0.0"
3838
guava = "com.google.guava:guava:30.1.1-jre"
3939
jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
40+
kotlin-annotationProcessingEmbeddable = { module = "org.jetbrains.kotlin:kotlin-annotation-processing-embeddable", version.ref = "kotlin" }
41+
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
4042
kotlin-compilerEmbeddable = { module = "org.jetbrains.kotlin:kotlin-compiler-embeddable", version.ref = "kotlin" }
4143
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
4244
kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" }
4345
kotlinpoet-metadata = { module = "com.squareup:kotlinpoet-metadata", version.ref = "kotlinpoet" }
4446
kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" }
45-
kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.5.0"
47+
kotlinxMetadata = "org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0"
4648
ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" }
4749
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
4850
okio = "com.squareup.okio:okio:2.10.0"
4951

5052
# Test libs
5153
assertj = "org.assertj:assertj-core:3.11.1"
5254
junit = "junit:junit:4.13.2"
53-
kotlinCompileTesting = { module = "com.github.tschuchortdev:kotlin-compile-testing", version.ref = "kotlinCompileTesting" }
54-
kotlinCompileTesting-ksp = { module = "com.github.tschuchortdev:kotlin-compile-testing-ksp", version.ref ="kotlinCompileTesting" }
55+
kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "kotlinCompileTesting" }
56+
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
5557
truth = "com.google.truth:truth:1.1.3"

kotlin/codegen/build.gradle.kts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ tasks.withType<KotlinCompile>().configureEach {
3232
"-opt-in=com.squareup.kotlinpoet.metadata.KotlinPoetMetadataPreview",
3333
"-opt-in=com.squareup.moshi.kotlin.codegen.api.InternalMoshiCodegenApi",
3434
)
35+
if (this@configureEach.name == "compileTestKotlin") {
36+
freeCompilerArgs += "-opt-in=org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi"
37+
}
3538
}
3639
}
3740

@@ -68,19 +71,24 @@ dependencies {
6871
implementation(libs.kotlinpoet.ksp)
6972
implementation(libs.guava)
7073
implementation(libs.asm)
74+
implementation(platform(libs.kotlin.bom))
7175

7276
implementation(libs.autoService)
7377
ksp(libs.autoService.ksp)
7478

7579
// KSP deps
7680
compileOnly(libs.ksp)
7781
compileOnly(libs.ksp.api)
82+
compileOnly(libs.kotlin.annotationProcessingEmbeddable)
7883
compileOnly(libs.kotlin.compilerEmbeddable)
84+
compileOnly(platform(libs.kotlin.bom))
7985
// Always force the latest KSP version to match the one we're compiling against
8086
testImplementation(libs.ksp)
8187
testImplementation(libs.ksp.api)
88+
testImplementation(libs.kotlin.annotationProcessingEmbeddable)
8289
testImplementation(libs.kotlin.compilerEmbeddable)
8390
testImplementation(libs.kotlinCompileTesting.ksp)
91+
testImplementation(platform(libs.kotlin.bom))
8492

8593
// Copy these again as they're not automatically included since they're shaded
8694
testImplementation(project(":moshi"))

kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/api/AdapterGenerator.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public class AdapterGenerator(
7272
"DEPRECATION",
7373
// Because we look it up reflectively
7474
"unused",
75+
"UNUSED_PARAMETER",
7576
// Because we include underscores
7677
"ClassName",
7778
// Because we generate redundant `out` variance for some generics and there's no way
@@ -258,8 +259,12 @@ public class AdapterGenerator(
258259

259260
val typeRenderer: TypeRenderer = object : TypeRenderer() {
260261
override fun renderTypeVariable(typeVariable: TypeVariableName): CodeBlock {
261-
val index = typeVariables.indexOfFirst { it == typeVariable }
262-
check(index != -1) { "Unexpected type variable $typeVariable" }
262+
// Match only by name because equality checks for more things than just the name. For example, a base class
263+
// may declare "T" but the subclass declares "T : Number", which is legal but will fail an equals() test.
264+
val index = typeVariables.indexOfFirst { it.name == typeVariable.name }
265+
check(index != -1) {
266+
"Unexpected type variable $typeVariable"
267+
}
263268
return CodeBlock.of("%N[%L]", typesParam, index)
264269
}
265270
}

kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/apt/JsonClassCodegenProcessor.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public class JsonClassCodegenProcessor : AbstractProcessor() {
7070

7171
override fun init(processingEnv: ProcessingEnvironment) {
7272
super.init(processingEnv)
73+
processingEnv.messager.printMessage(Diagnostic.Kind.WARNING, "Kapt support in Moshi Kotlin Code Gen is deprecated and will be removed in 2.0. Please migrate to KSP. https://github.com/square/moshi#codegen")
7374
generatedType = processingEnv.options[OPTION_GENERATED]?.let {
7475
POSSIBLE_GENERATED_NAMES[it] ?: error(
7576
"Invalid option value for $OPTION_GENERATED. Found $it, " +

kotlin/codegen/src/main/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ private class JsonClassSymbolProcessor(
8787

8888
if (!jsonClassAnnotation.generateAdapter) continue
8989

90-
val originatingFile = type.containingFile!!
91-
val adapterGenerator = adapterGenerator(logger, resolver, type) ?: return emptyList()
9290
try {
91+
val originatingFile = type.containingFile!!
92+
val adapterGenerator = adapterGenerator(logger, resolver, type) ?: return emptyList()
9393
val preparedAdapter = adapterGenerator
9494
.prepare(generateProguardRules) { spec ->
9595
spec.toBuilder()

kotlin/codegen/src/test/java/com/squareup/moshi/kotlin/codegen/ksp/JsonClassSymbolProcessorTest.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,24 @@ class JsonClassSymbolProcessorTest {
537537
assertThat(result.messages).contains("JsonQualifier @UpperCase must have RUNTIME retention")
538538
}
539539

540+
@Test
541+
fun invalidGenericSyntaxErrorMessaging() {
542+
val result = compile(
543+
kotlin(
544+
"source.kt",
545+
"""
546+
package test
547+
import com.squareup.moshi.JsonClass
548+
549+
@JsonClass(generateAdapter = true)
550+
data class ElementEnvelope(val elements: List)
551+
""",
552+
),
553+
)
554+
assertThat(result.exitCode).isEqualTo(KotlinCompilation.ExitCode.COMPILATION_ERROR)
555+
assertThat(result.messages).contains("Error preparing ElementEnvelope")
556+
}
557+
540558
@Test
541559
fun `TypeAliases with the same backing type should share the same adapter`() {
542560
val result = compile(

moshi/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ val java16 by sourceSets.creating {
2828
}
2929
}
3030

31+
tasks.named<JavaCompile>("compileJava16Java") {
32+
options.release.set(16)
33+
}
34+
3135
tasks.named<JavaCompile>("compileJava16Java") {
3236
// We use JDK 17 for latest but target 16 for maximum compatibility
3337
javaCompiler.set(

0 commit comments

Comments
 (0)