Skip to content

Commit

Permalink
Omit stdlib from compiler and gradle artifact deps (#587)
Browse files Browse the repository at this point in the history
* Finish missing test bits

* Omit stdlib dep from gradle and compiler deps
  • Loading branch information
ZacSweers committed May 12, 2024
1 parent 0127d39 commit c8dfdcd
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 1 deletion.
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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:<version>")
}
```

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
------

Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<Int>,
val set: ImmutableSet<Int>,
val collection: ImmutableCollection<Int>,
Expand Down
1 change: 1 addition & 0 deletions moshi-ir/moshi-compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ tasks.withType<Test>().configureEach {
}

dependencies {
compileOnly(libs.kotlin.stdlib)
compileOnly(libs.kotlin.compilerEmbeddable)
implementation(libs.autoService)
implementation(libs.moshi)
Expand Down
3 changes: 3 additions & 0 deletions moshi-ir/moshi-compiler-plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions moshi-ir/moshi-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
3 changes: 3 additions & 0 deletions moshi-ir/moshi-gradle-plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c8dfdcd

Please sign in to comment.