diff --git a/CHANGELOG.md b/CHANGELOG.md index ff8743e2..5a3afa70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,39 @@ Changelog ========= +**Unreleased** +-------------- + +### **New**: Publish a new `moshi-immutable-adapters` artifact with support for [kotlinx.collections.immutable](https://github.com/Kotlin/kotlinx.collections.immutable). + +Gradle dependency + +```kotlin +dependencies { + implementation("dev.zacsweers.moshix:moshi-immutable-adapters:") +} +``` + +In code + +```kotlin +val moshi = Moshi.Builder().add(ImmutableCollectionsJsonAdapterFactory()).build() +``` + +**Supported types** + +- `ImmutableCollection` +- `ImmutableList` +- `ImmutableSet` +- `ImmutableMap` +- `PersistentCollection` +- `PersistentList` +- `PersistentSet` +- `PersistentMap` + +### Misc +- Omit the stdlib from transitive dependencies on the compiler plugin and Gradle plugin artifacts. Both kotlinc and Gradle impose their own versions on the classpath. + 0.25.1 ------ diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fed11253..bc1a95fb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -60,6 +60,7 @@ kotlin-metadata = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", versi kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } kotlin-gradlePlugin-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" } +kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } kotlinx-immutable = "org.jetbrains.kotlinx:kotlinx-collections-immutable:0.3.7" kotlinpoet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoet" } diff --git a/moshi-immutable-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/immutable/ImmutableCollectionsJsonAdapterFactoryTest.kt b/moshi-immutable-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/immutable/ImmutableCollectionsJsonAdapterFactoryTest.kt index 49b4827c..e5660a4c 100644 --- a/moshi-immutable-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/immutable/ImmutableCollectionsJsonAdapterFactoryTest.kt +++ b/moshi-immutable-adapters/src/test/kotlin/dev/zacsweers/moshix/adapters/immutable/ImmutableCollectionsJsonAdapterFactoryTest.kt @@ -1,5 +1,6 @@ package dev.zacsweers.moshix.adapters.immutable +import com.google.common.truth.Truth.assertThat import com.squareup.moshi.Moshi import com.squareup.moshi.adapter import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory @@ -84,9 +85,12 @@ class ImmutableCollectionsJsonAdapterFactoryTest { "c" to persistentListOf(1, 2, 3), ), ) + assertThat(instance).isEqualTo(expectedInstance) + val serializedAndReserializedInstance = adapter.fromJson(adapter.toJson(expectedInstance))!! + assertThat(serializedAndReserializedInstance).isEqualTo(expectedInstance) } - class ClassWithImmutables( + data class ClassWithImmutables( val list: ImmutableList, val set: ImmutableSet, val collection: ImmutableCollection, diff --git a/moshi-ir/moshi-compiler-plugin/build.gradle.kts b/moshi-ir/moshi-compiler-plugin/build.gradle.kts index 9b2798b2..7ce7a971 100644 --- a/moshi-ir/moshi-compiler-plugin/build.gradle.kts +++ b/moshi-ir/moshi-compiler-plugin/build.gradle.kts @@ -34,6 +34,7 @@ tasks.withType().configureEach { } dependencies { + compileOnly(libs.kotlin.stdlib) compileOnly(libs.kotlin.compilerEmbeddable) implementation(libs.autoService) implementation(libs.moshi) diff --git a/moshi-ir/moshi-compiler-plugin/gradle.properties b/moshi-ir/moshi-compiler-plugin/gradle.properties index eec61c9a..432dc01a 100644 --- a/moshi-ir/moshi-compiler-plugin/gradle.properties +++ b/moshi-ir/moshi-compiler-plugin/gradle.properties @@ -1,3 +1,6 @@ POM_NAME=Moshi Compiler Plugin POM_ARTIFACT_ID=moshi-compiler-plugin POM_PACKAGING=jar + +# kotlinc imposes its own +kotlin.stdlib.default.dependency=false diff --git a/moshi-ir/moshi-gradle-plugin/build.gradle.kts b/moshi-ir/moshi-gradle-plugin/build.gradle.kts index 8958fb29..e70a66f4 100644 --- a/moshi-ir/moshi-gradle-plugin/build.gradle.kts +++ b/moshi-ir/moshi-gradle-plugin/build.gradle.kts @@ -107,6 +107,7 @@ spotless { dependencies { compileOnly(libs.kotlin.gradlePlugin) compileOnly(libs.kotlin.gradlePlugin.api) + compileOnly(libs.kotlin.stdlib) compileOnly(libs.ksp.gradlePlugin) compileOnly(libs.agp) } diff --git a/moshi-ir/moshi-gradle-plugin/gradle.properties b/moshi-ir/moshi-gradle-plugin/gradle.properties index 30e80f62..8bf351de 100644 --- a/moshi-ir/moshi-gradle-plugin/gradle.properties +++ b/moshi-ir/moshi-gradle-plugin/gradle.properties @@ -2,6 +2,9 @@ POM_NAME=Moshi Gradle Plugin POM_ARTIFACT_ID=moshi-gradle-plugin POM_PACKAGING=jar +# Gradle imposes its own +kotlin.stdlib.default.dependency=false + GROUP=dev.zacsweers.moshix VERSION_NAME=0.26.0-SNAPSHOT POM_DESCRIPTION=A Kotlin compiler plugin that generates Moshi JsonAdapter classes.