-
Notifications
You must be signed in to change notification settings - Fork 123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for Kotlin Serialization? #267
Comments
Couldn't this be configured with an option parameter? Either for the compiler or runtime. kscript supports both, see the examples under |
Interesting! You are right -- on a closer look, I could get it to work, although it's a bit of a hack since I need to hardcode a path to the jar. #!/usr/bin/env kscript
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0", "org.jetbrains.kotlin:kotlin-maven-serialization:1.3.72")
@file:CompilerOpts("-Xplugin=/home/knuckles/.m2/repository/org/jetbrains/kotlin/kotlin-maven-serialization/1.3.72/kotlin-maven-serialization-1.3.72.jar")
import kotlinx.serialization.*
import kotlinx.serialization.json.*
@Serializable
data class Data(val a: Int, val b: String = "42")
fun main() {
// Json also has .Default configuration which provides more reasonable settings,
// but is subject to change in future versions
val json = Json(JsonConfiguration.Stable)
// serializing objects
val jsonData = json.stringify(Data.serializer(), Data(42))
// serializing lists
println(jsonData) // {"a": 42, "b": "42"}
// parsing data back
val obj = json.parse(Data.serializer(), """{"a":42}""") // b is optional since it has default value
println(obj) // Data(a=42, b="42")
}
main() Is there a way to make this a bit more portable? |
No clue. I've forwarded the question to the experts https://kotlinlang.slack.com/archives/C7A1U5PTM/p1593722985324800 |
This doesn't seem to work anymore: |
I managed to get this approach to work, thanks! I have one question, though. Since I'm hoping to make this script portable, I don't really want to hard-code my own home path. Is there any way to interpolate the user's home path in the annotation string? The following actually does work: @file:CompilerOpts("-Xplugin=$HOME/.m2/repository/org/jetbrains/kotlin/kotlin-maven-serialization/1.7.20/kotlin-maven-serialization-1.7.20.jar") However, it makes IntelliJ really angry: I also tried Has anyone figured out to make this work without infuriating IntelliJ? |
## Task Resolves: #44 ## Description All versions will now be configured in the `src/main/resources/version-config.json` file. There are two release paths: 1. If you want update provider schemas and build new versions of the libraries, run the Gradle task `prepareReleaseOfUpdatedSchemas`. 2. If you want to release a new version of all libraries due to some update in our generator, run the Gradle task `prepareReleaseAfterGeneratorUpdate`. These tasks will create a new commit which updates the versions in `version-config.json` accordingly. Push this commit out to a new branch and create a PR (like [this one](#98)). Once this PR is approved and merged, a GitHub Action will be triggered (like [this one](https://github.com/VirtuslabRnD/pulumi-kotlin/actions/runs/3328060887)), which will: 1. Tag the merge commit with the appropriate release versions. 2. Release the requested libraries to the [Packages](https://github.com/orgs/VirtuslabRnD/packages?repo_name=pulumi-kotlin) section on GitHub. 3. Fast-forward the released versions to SNAPSHOT versions and create a PR (like [this one](#99)). Once this PR is approved and merged, the release cycle is complete. In the future, the task `prepareReleaseOfUpdatedSchemas` could be run automatically as a cron job. For now, it will need to be run manually by one of the team members. ## Useful links ### Serialization in Gradle scripts - https://discuss.gradle.org/t/how-to-apply-kotlin-serialization-in-buildscript/41171 - https://slack-chats.kotlinlang.org/t/544960/i-m-trying-to-upgrade-kotlin-to-1-7-0-and-i-m-no-longer-able ### Maven versioning - https://stackoverflow.com/questions/13004443/how-does-maven-sort-version-numbers/31482463#31482463 ### KScript adventures - kscripting/kscript#267 - kscripting/kscript#191 ### Publishing libraries - https://docs.github.com/en/actions/publishing-packages/publishing-java-packages-with-gradle#publishing-packages-to-github-packages - https://github.com/orgs/community/discussions/13836 ### JGit - https://www.nuxeo.com/blog/jgit-example/
I know it's pretty late, but I found that you could use @file:DependsOn("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.0", "org.jetbrains.kotlin:kotlin-maven-serialization:1.9.0")
@file:CompilerOptions("-Xplugin=$(echo ~)/.m2/repository/org/jetbrains/kotlin/kotlin-maven-serialization/1.9.0/kotlin-maven-serialization-1.9.0.jar") It also works with |
Hello there, and thanks for kscript!
I would like to request the addition of support for Kotlin Serialization. Since it needs an extra plug-in during compilation, I couldn't see any way to use it when using kscript.
The text was updated successfully, but these errors were encountered: