0

I'm trying to use the Kotlinx Serialization libraries and the associated Gradle plugin. It's supposed to generate serializers for when when I annotate a class with @Serializable, like this:

@Serializable
data class Message(val version: String)

// (...)

Json.encodeToString(Message("1.0"))

It does not work, and the annotation is highlighted with:

kotlinx.serialization compiler plugin is not applied to the module, so this annotation would not be processed. Make sure that you've setup your buildscript correctly and re-import project.

As expected, the code does not compile as I'm expecting to use the Serializers further down the line, with the error:

Type mismatch: inferred type is Message but SerializationStrategy<TypeVariable(T)> was expected

Here is my app-level build.gradle:

plugins {
    id "java"
    id 'org.jetbrains.kotlin.jvm' version '1.6.10'
    id 'org.jetbrains.kotlin.plugin.serialization' version '1.6.10'
}

kotlin {
    jvmToolchain {
        languageVersion.set(JavaLanguageVersion.of(11))
    }
}

dependencies {
    implementation "com.amazonaws:aws-lambda-java-core:$lambda_runtime_version"
    implementation "software.amazon.awssdk:dynamodb-enhanced:$aws_sdk_version"
    implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:$kotlin_serialization_version"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

task fatJar(type: Jar) {
    archiveClassifier = 'lambdaCode'
    duplicatesStrategy = DuplicatesStrategy.WARN
    from sourceSets.main.output
    dependsOn configurations.runtimeClasspath
    from {
        configurations.runtimeClasspath.findAll { it.name.endsWith('jar') }.collect { zipTree(it) }
    }
}

I'm using Gradle 7.3.3, and see all this in IntelliJ. I tried launching gradle build from the command line, with similar results, so the IDE does not seem to blame.

I read a lot of similar questions but I could not find an answer that worked for me. Can anyone shed some light on my situation?

Silver Quettier
  • 2,045
  • 2
  • 26
  • 53

0 Answers0