Skip to content

Commit

Permalink
Move to kotlinx.serialization (apollographql#4726)
Browse files Browse the repository at this point in the history
* replace Moshi with kotlinx.serialization

* remove (most of moshi)
  • Loading branch information
martinbonnin authored Mar 6, 2023
1 parent 70d1205 commit 3b4e435
Show file tree
Hide file tree
Showing 28 changed files with 237 additions and 215 deletions.
7 changes: 4 additions & 3 deletions benchmark/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ apply(plugin = "org.jetbrains.kotlin.android")

configure<com.android.build.gradle.AppExtension> {
namespace = "com.apollographql.apollo3.emptyapp"
compileSdkVersion(golatac.version("android.sdkversion.compile").toInt())

compileSdkVersion(libs.versions.android.sdkversion.compile.get().toInt())

defaultConfig {
minSdkVersion(golatac.version("android.sdkversion.min"))
targetSdkVersion(golatac.version("android.sdkversion.target"))
minSdk = libs.versions.android.sdkversion.min.get().toInt()
targetSdk = libs.versions.android.sdkversion.target.get().toInt()

val debugSigningConfig = signingConfigs.getByName("debug").apply {
// This is all public. This app is only an empty shell to make Firebase happy because it requires an 'app' APK.
Expand Down
28 changes: 8 additions & 20 deletions benchmark/build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
plugins {
`embedded-kotlin`
id("net.mbonnin.golatac") version "0.0.3"
}

golatac.init(file("../../gradle/libraries.toml"))

group = "com.apollographql.apollo3.benchmark"

repositories {
mavenCentral()
google()
maven {
url = uri("../../build/localMaven")
}
}

dependencies {
compileOnly(gradleApi())
implementation(golatac.lib("kotlin.plugin"))
implementation("com.squareup.okio:okio-jvm:3.2.0")
implementation(golatac.lib("ksp"))
implementation("me.lucko:jar-relocator:1.5")

implementation(libs.kotlin.plugin)
implementation(libs.okio)
implementation(libs.ksp)
implementation(benchmarks.jar.relocator)
if (true) {
implementation(golatac.lib("apollo.plugin"))
implementation(libs.apollo.plugin)
} else {
implementation("com.apollographql.apollo3:apollo-gradle-plugin:3.4.0")
}
implementation("androidx.benchmark:benchmark-gradle-plugin:1.1.0")
implementation("com.android.tools.build:gradle:7.4.0-alpha09")
implementation("org.ow2.asm:asm-commons:9.2")
implementation(benchmarks.benchmark.gradle.plugin)
implementation(benchmarks.agp)
implementation(benchmarks.asm)
}
25 changes: 17 additions & 8 deletions benchmark/build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal {
content {
includeModule("org.gradle.kotlin.embedded-kotlin", "org.gradle.kotlin.embedded-kotlin.gradle.plugin")
includeGroup("org.gradle.kotlin")
}
apply(from = "../../gradle/repositories.gradle.kts")

listOf(pluginManagement.repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
maven {
url = uri("../../build/localMaven")
}
}
}

dependencyResolutionManagement {
versionCatalogs {
create("benchmarks") {
from(files("../gradle/benchmarks.versions.toml"))
}
create("libs") {
from(files("../../gradle/libraries.toml"))
}
}
}
16 changes: 0 additions & 16 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
buildscript {
repositories {
mavenCentral()
google()
maven {
url = uri("../build/localMaven")
}
}
dependencies {
classpath("com.apollographql.apollo3.benchmark:build-logic")
}
Expand All @@ -17,12 +10,3 @@ plugins {

golatac.init(file("../gradle/libraries.toml"))

allprojects {
repositories {
mavenCentral()
google()
maven {
url = rootProject.uri("../build/localMaven")
}
}
}
11 changes: 11 additions & 0 deletions benchmark/gradle/benchmarks.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[versions]
moshix = "0.14.1"

[libraries]
jar-relocator = "me.lucko:jar-relocator:1.5"
benchmark-gradle-plugin = "androidx.benchmark:benchmark-gradle-plugin:1.1.1"
agp = "com.android.tools.build:gradle:7.4.2"
asm = "org.ow2.asm:asm-commons:9.3"
moshix-ksp = { group = "dev.zacsweers.moshix", name = "moshi-ksp", version.ref = "moshix" }
benchmark-junit4 = "androidx.benchmark:benchmark-junit4:1.1.1"
androidx-test-core = "androidx.test:core:1.5.0"
8 changes: 4 additions & 4 deletions benchmark/microbenchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ dependencies {
}
}
}
implementation(golatac.lib("moshi"))
ksp(golatac.lib("moshix.ksp"))
implementation(libs.moshi)
ksp(benchmarks.moshix.ksp)

androidTestImplementation("androidx.benchmark:benchmark-junit4:1.1.0")
androidTestImplementation("androidx.test:core:1.4.0")
androidTestImplementation(benchmarks.benchmark.junit4)
androidTestImplementation(benchmarks.androidx.test.core)
}

configure<com.android.build.gradle.LibraryExtension> {
Expand Down
23 changes: 20 additions & 3 deletions benchmark/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,25 @@ include(":app", ":microbenchmark")

includeBuild("build-logic")

pluginManagement {
repositories {
mavenCentral()

apply(from = "../gradle/repositories.gradle.kts")

listOf(pluginManagement.repositories, dependencyResolutionManagement.repositories).forEach {
it.apply {
maven {
url = uri("../build/localMaven")
}
}
}


dependencyResolutionManagement {
versionCatalogs {
create("benchmarks") {
from(files("gradle/benchmarks.versions.toml"))
}
create("libs") {
from(files("../gradle/libraries.toml"))
}
}
}
4 changes: 3 additions & 1 deletion build-logic/src/main/kotlin/CompilerOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fun Project.configureJavaAndKotlinCompilers() {
apiVersion = "1.5"
languageVersion = "1.5"

(this as? KotlinJvmOptions)?.jvmTarget = "1.8"
(this as? KotlinJvmOptions)?.let {
it.jvmTarget = "1.8"
}
}
}
tasks.withType(KotlinNativeCompile::class.java).configureEach {
Expand Down
8 changes: 2 additions & 6 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ kotlinx-datetime = "0.4.0"
kotlinx-serialization-runtime = "1.4.1"
ksp = "1.8.20-Beta-1.0.9"
ktor = "2.2.2"
moshi = "1.12.0"
moshix = "0.14.1"
okhttp = "4.9.3"
rx-android = "2.0.1"
rx-java2 = "2.2.21"
Expand Down Expand Up @@ -116,14 +114,12 @@ kotlinx-serialization-json-okio = { group = "org.jetbrains.kotlinx", name = "kot
kotlinx-binarycompatibilityvalidator = { group = "org.jetbrains.kotlinx", name = "binary-compatibility-validator", version = "0.10.1" }
ksp = { group = "com.google.devtools.ksp", name = "symbol-processing-gradle-plugin", version.ref = "ksp" }
ktor-client-js = { group = "io.ktor", name = "ktor-client-js", version.ref = "ktor" }
moshi = { group = "com.squareup.moshi", name = "moshi", version.ref = "moshi" }
moshix-ksp = { group = "dev.zacsweers.moshix", name = "moshi-ksp", version.ref = "moshix" }
moshix-sealed-codegen = { group = "dev.zacsweers.moshix", name = "moshi-sealed-codegen", version.ref = "moshix" }
moshix-sealed-runtime = { group = "dev.zacsweers.moshix", name = "moshi-sealed-runtime", version.ref = "moshix" }
okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
okhttp-logging = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttp" }
okhttp-mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver", version.ref = "okhttp" }
okhttp-tls = { group = "com.squareup.okhttp3", name = "okhttp-tls", version.ref = "okhttp" }
moshi = { group = "com.squareup.moshi", name = "moshi", version = "1.12.0" }
okio = "com.squareup.okio:okio-jvm:3.3.0"
poet-java = { group = "com.squareup", name = "javapoet", version.ref = "javaPoet" }
poet-kotlin = { group = "com.squareup", name = "kotlinpoet", version = "1.12.0" }
rx-java2 = { group = "io.reactivex.rxjava2", name = "rxjava", version.ref = "rx-java2" }
Expand Down
2 changes: 1 addition & 1 deletion libraries/apollo-ast/api/apollo-ast.api
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,7 @@ public final class com/apollographql/apollo3/ast/introspection/IntrospectionSche
public static final fun toIntrospectionSchema (Lokio/BufferedSource;Ljava/lang/String;)Lcom/apollographql/apollo3/ast/introspection/IntrospectionSchema;
public static synthetic fun toIntrospectionSchema$default (Lokio/BufferedSource;Ljava/lang/String;ILjava/lang/Object;)Lcom/apollographql/apollo3/ast/introspection/IntrospectionSchema;
public static final fun toJson (Lcom/apollographql/apollo3/ast/introspection/IntrospectionSchema;)Ljava/lang/String;
public static final fun toJson (Lcom/apollographql/apollo3/ast/introspection/IntrospectionSchema;Ljava/io/File;)V
public static final fun writeTo (Lcom/apollographql/apollo3/ast/introspection/IntrospectionSchema;Ljava/io/File;)V
}

public final class com/apollographql/apollo3/ast/introspection/Introspection_to_schemaKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ fun IntrospectionSchema.toJson(): String {
return json.encodeToString(IntrospectionSchema.serializer(), this)
}

fun IntrospectionSchema.toJson(file: File) {
fun IntrospectionSchema.writeTo(file: File) {
file.outputStream().sink().buffer().use {
it.writeUtf8(json.encodeToString(IntrospectionSchema.serializer(), this))
}
Expand Down
76 changes: 50 additions & 26 deletions libraries/apollo-compiler/api/apollo-compiler.api
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,29 @@ public abstract interface class com/apollographql/apollo3/compiler/ApolloCompile
}

public final class com/apollographql/apollo3/compiler/CodegenMetadata {
public static final field Companion Lcom/apollographql/apollo3/compiler/CodegenMetadata$Companion;
public synthetic fun <init> (ILcom/apollographql/apollo3/compiler/codegen/ResolverInfo;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public final fun copy (Lcom/apollographql/apollo3/compiler/codegen/ResolverInfo;)Lcom/apollographql/apollo3/compiler/CodegenMetadata;
public static synthetic fun copy$default (Lcom/apollographql/apollo3/compiler/CodegenMetadata;Lcom/apollographql/apollo3/compiler/codegen/ResolverInfo;ILjava/lang/Object;)Lcom/apollographql/apollo3/compiler/CodegenMetadata;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/apollographql/apollo3/compiler/CodegenMetadata;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/apollographql/apollo3/compiler/CodegenMetadataJsonAdapter : com/squareup/moshi/JsonAdapter {
public fun <init> (Lcom/squareup/moshi/Moshi;)V
public fun fromJson (Lcom/squareup/moshi/JsonReader;)Lcom/apollographql/apollo3/compiler/CodegenMetadata;
public synthetic fun fromJson (Lcom/squareup/moshi/JsonReader;)Ljava/lang/Object;
public fun toJson (Lcom/squareup/moshi/JsonWriter;Lcom/apollographql/apollo3/compiler/CodegenMetadata;)V
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
public fun toString ()Ljava/lang/String;
public final class com/apollographql/apollo3/compiler/CodegenMetadata$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/apollographql/apollo3/compiler/CodegenMetadata$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/apollographql/apollo3/compiler/CodegenMetadata;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/apollographql/apollo3/compiler/CodegenMetadata;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/CodegenMetadata$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/CodegenMetadataKt {
Expand Down Expand Up @@ -140,10 +149,6 @@ public final class com/apollographql/apollo3/compiler/KotlinCodegenOptions {
public final fun getSealedClassesForEnumsMatching ()Ljava/util/List;
}

public final class com/apollographql/apollo3/compiler/MoshiKt {
public static final fun getMOSHI ()Lcom/squareup/moshi/Moshi;
}

public abstract interface class com/apollographql/apollo3/compiler/OperationIdGenerator {
public static final field Companion Lcom/apollographql/apollo3/compiler/OperationIdGenerator$Companion;
public abstract fun apply (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
Expand Down Expand Up @@ -302,6 +307,8 @@ public final class com/apollographql/apollo3/compiler/VersionKt {
}

public final class com/apollographql/apollo3/compiler/codegen/ResolverKey {
public static final field Companion Lcom/apollographql/apollo3/compiler/codegen/ResolverKey$Companion;
public synthetic fun <init> (ILcom/apollographql/apollo3/compiler/codegen/ResolverKeyKind;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Lcom/apollographql/apollo3/compiler/codegen/ResolverKeyKind;Ljava/lang/String;)V
public final fun component1 ()Lcom/apollographql/apollo3/compiler/codegen/ResolverKeyKind;
public final fun component2 ()Ljava/lang/String;
Expand All @@ -312,15 +319,22 @@ public final class com/apollographql/apollo3/compiler/codegen/ResolverKey {
public final fun getKind ()Lcom/apollographql/apollo3/compiler/codegen/ResolverKeyKind;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/apollographql/apollo3/compiler/codegen/ResolverKey;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/apollographql/apollo3/compiler/codegen/ResolverKeyJsonAdapter : com/squareup/moshi/JsonAdapter {
public fun <init> (Lcom/squareup/moshi/Moshi;)V
public fun fromJson (Lcom/squareup/moshi/JsonReader;)Lcom/apollographql/apollo3/compiler/codegen/ResolverKey;
public synthetic fun fromJson (Lcom/squareup/moshi/JsonReader;)Ljava/lang/Object;
public fun toJson (Lcom/squareup/moshi/JsonWriter;Lcom/apollographql/apollo3/compiler/codegen/ResolverKey;)V
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
public fun toString ()Ljava/lang/String;
public final class com/apollographql/apollo3/compiler/codegen/ResolverKey$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/apollographql/apollo3/compiler/codegen/ResolverKey$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/apollographql/apollo3/compiler/codegen/ResolverKey;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/apollographql/apollo3/compiler/codegen/ResolverKey;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/codegen/ResolverKey$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/codegen/ResolverKeyKind : java/lang/Enum {
Expand Down Expand Up @@ -400,22 +414,32 @@ public final class com/apollographql/apollo3/compiler/ir/IrSchemaBuilder {
}

public final class com/apollographql/apollo3/compiler/operationoutput/OperationDescriptor {
public static final field Companion Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor$Companion;
public synthetic fun <init> (ILjava/lang/String;Ljava/lang/String;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/String;)V
public final fun getName ()Ljava/lang/String;
public final fun getSource ()Ljava/lang/String;
public static final synthetic fun write$Self (Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor;Lkotlinx/serialization/encoding/CompositeEncoder;Lkotlinx/serialization/descriptors/SerialDescriptor;)V
}

public final class com/apollographql/apollo3/compiler/operationoutput/OperationDescriptorJsonAdapter : com/squareup/moshi/JsonAdapter {
public fun <init> (Lcom/squareup/moshi/Moshi;)V
public fun fromJson (Lcom/squareup/moshi/JsonReader;)Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor;
public synthetic fun fromJson (Lcom/squareup/moshi/JsonReader;)Ljava/lang/Object;
public fun toJson (Lcom/squareup/moshi/JsonWriter;Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor;)V
public synthetic fun toJson (Lcom/squareup/moshi/JsonWriter;Ljava/lang/Object;)V
public fun toString ()Ljava/lang/String;
public final class com/apollographql/apollo3/compiler/operationoutput/OperationDescriptor$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
public static final field INSTANCE Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor$$serializer;
public fun childSerializers ()[Lkotlinx/serialization/KSerializer;
public fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor;
public synthetic fun deserialize (Lkotlinx/serialization/encoding/Decoder;)Ljava/lang/Object;
public fun getDescriptor ()Lkotlinx/serialization/descriptors/SerialDescriptor;
public fun serialize (Lkotlinx/serialization/encoding/Encoder;Lcom/apollographql/apollo3/compiler/operationoutput/OperationDescriptor;)V
public synthetic fun serialize (Lkotlinx/serialization/encoding/Encoder;Ljava/lang/Object;)V
public fun typeParametersSerializers ()[Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/operationoutput/OperationDescriptor$Companion {
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class com/apollographql/apollo3/compiler/operationoutput/OperationOutputKt {
public static final fun findOperationId (Ljava/util/Map;Ljava/lang/String;)Ljava/lang/String;
public static final fun toOperationOutput (Lokio/BufferedSource;)Ljava/util/Map;
public static final fun toOperationOutput (Ljava/io/File;)Ljava/util/Map;
public static final fun writeTo (Ljava/util/Map;Ljava/io/File;)V
}

6 changes: 0 additions & 6 deletions libraries/apollo-compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("org.jetbrains.kotlin.jvm")
id("apollo.library")
id("com.google.devtools.ksp")
id("org.jetbrains.kotlin.plugin.serialization")
}

Expand All @@ -22,14 +21,9 @@ dependencies {
}
api(golatac.lib("poet.java"))

implementation(golatac.lib("moshi"))
implementation(golatac.lib("moshix.sealed.runtime"))
implementation(golatac.lib("kotlinx.serialization.json"))
implementation(golatac.lib("kotlinx.serialization.json.okio"))

ksp(golatac.lib("moshix.sealed.codegen"))
ksp(golatac.lib("moshix.ksp"))

testImplementation(golatac.lib("kotlin.compiletesting"))
testImplementation(golatac.lib("google.testing.compile"))
testImplementation(golatac.lib("truth"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.apollographql.apollo3.compiler.ir.IrSchemaBuilder
import com.apollographql.apollo3.compiler.ir.toIrOperations
import com.apollographql.apollo3.compiler.operationoutput.OperationDescriptor
import com.apollographql.apollo3.compiler.operationoutput.OperationOutput
import com.apollographql.apollo3.compiler.operationoutput.writeTo
import okio.buffer
import okio.source
import java.io.File
Expand Down Expand Up @@ -271,7 +272,9 @@ object ApolloCompiler {
""".trimMargin()
}

operationOutputFile?.writeText(operationOutput.toJson(" "))
if (operationOutputFile != null) {
operationOutput.writeTo(operationOutputFile)
}

return operationOutput
}
Expand Down
Loading

0 comments on commit 3b4e435

Please sign in to comment.