Is it possible to apply the KotlinX.Serialization plugin only to test sources (
commonTest
,
jvmTest
…)?
s
sandwwraith
08/12/2025, 3:33 PM
No. However, without any
@Serializable
annotations, plugin will not perform code transformations.
You can try to add runtime dependency to test sources only. It is not recommended, but will probably work.
c
CLOVIS
08/12/2025, 3:35 PM
For context, it's a library that doesn't use KotlinX.Serialization directly, but through the strategy pattern it may be asked to serialize elements indirectly. I'd like to create
@Serializable
classes in the library's test sources, without the exported files having any dependency on KxS.
r
russhwolf
08/12/2025, 4:25 PM
You could also try defining your serializable classes in a separate module where you apply the plugin, then depend on that module from your test sources
c
CLOVIS
08/12/2025, 4:29 PM
There are only ~5 of these classes so that sounds overkill, but it is conceptually simple so I may end up with that