Trying to figure out how to add kotlinx.serializat...
# scripting
s
Trying to figure out how to add kotlinx.serialization plugin to kotlin scripting. Is it something like this?
--P plugin:serialization
s
Thanks, yeah, I saw that but still don't quite understand what to do, was hoping for a practical example because still a little fuzzy how that test can be used to get it to work
n
kotlinc -Xplugin /path/to/serializationplugin
+ the usual arguments
whatever
KotlinPaths.Jar.SerializationPlugin
is in that code.. i assume it is bundled in the kotlin install along with kotlinc though
s
Copy code
@file:CompilerOptions("-Xplugin kotlinx-serialization-compiler.jar")
I tried from command line and using scripting annotation. Think I 'm still missing something
Hoping someone a bit more experienced with compiler options can figure it out and give a concrete example
b
I've been using this shebang. Definitely interested in the CompilerOptions annotation though, if anyone knows how to get that working
#!/usr/bin/env -S kotlinc -script -Xplugin="${KOTLIN_HOME}/lib/kotlinx-serialization-compiler-plugin.jar" --
(only works if executed directly from the shell:
./my-script.main.kts
)
s
Thanks, still getting the same error when I try to use
@Serialize
annotation for my data class. Maybe you can post a minimal example of how you are using it? I added the shebang and executed from command line as described.
r
I don't have an example, unfortunately. Some ideas: Does
${KOTLIN_HOME}/lib/kotlinx-serialization-compiler-plugin.jar
exist? Does your code work in a non-script project?
b
The IDE won't know about the serialization plugin, so it'll show errors for things like Class.serializer(). It should run fine though. You should also make sure KOTLIN_HOME is defined in your shell environment. You can test with
echo $KOTLIN_HOME
and make sure it prints a path.