1

How does one go about using the kotlinx.serialization library with Bazel's rules_kotlin?

This is what I've tried:

java_plugin(
    name = "grrr_plugin",
    processor_class = "org.jetbrains.kotlinx.serialization.compiler.backend.jvm.SerializableCodegenImpl",
    deps = ["@maven//:org_jetbrains_kotlin_kotlin_maven_serialization"],
)

kt_jvm_library(
    name = "dto",
    srcs = ["src/main/kotlin/Dto.kt"],
    plugins = [":grrr_plugin"],
    deps = [
        "//proto:market_java_proto",
        "@maven//:org_jetbrains_kotlin_kotlin_maven_serialization",
        "@maven//:org_jetbrains_kotlinx_kotlinx_serialization_runtime",
    ],
)

@Serializable
data class Foo(val id: String, val bar: Int)

, where Foo is a class in the :dto package.

I can build the dto library, but I get

unresolved reference: serializer
    val jsonData = json.stringify(Foo.serializer(), foo)

when I use the dto library in other packages.

mancini0
  • 4,285
  • 1
  • 29
  • 31

0 Answers0