How to setup serialization in IntelliJ/Kotlin?

后端 未结 1 1877
走了就别回头了
走了就别回头了 2021-01-15 23:36

My apologies for a noob question: I\'m trying to check out how serialization works in Kotlin.

To this end, I created a Gradle project like this:

edi

相关标签:
1条回答
  • 2021-01-16 00:13

    Finally, figured it out. A BUG in IntelliJ IDEA was foiling my troubleshooting.

    Leaving the answer for anyone who might find this question via Google:

    build.gradle.kt needs to be

    plugins {
        java
        kotlin("jvm") version "1.3.71"
        kotlin("plugin.serialization") version "1.3.71"
    }
    
    repositories {
        // artifacts are published to JCenter
        jcenter()
    }
    
    dependencies {
        implementation(kotlin("stdlib", org.jetbrains.kotlin.config.KotlinCompilerVersion.VERSION))
        implementation("org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.20.0")
    }
    

    The official instructions have a buggy version of this: no org.jetbrains.kotlin.config.

    However, this is not enough. I was executing "Run" from the Kotlin file. This leads to another error

    error: unable to evaluate script, no scripting plugin loaded
    

    due to a nasty bug (as in, I wasted HOURS and HOURS trying to figure out what I was doing wrong) https://youtrack.jetbrains.com/issue/KT-37814

    One needs to explicitly execute "Build project".

    0 讨论(0)
提交回复
热议问题