In a new IntelliJ kotlin multiplatform project aft...
# serialization
m
In a new IntelliJ kotlin multiplatform project after adding
kotlin("plugin.serialization")
and serialization dependency in common module I don't get generated serializers and get a warning on
@Serializable
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.
The main build.gradle.kts contains proper buildscript dependencies
Copy code
classpath(kotlin("gradle-plugin", version = "1.4.31"))
classpath(kotlin("plugin.serialization", version = "1.4.31"))
Nothing seems to help. I've removed all unnecessary code, reimported project, invalidated caches but to no avail. Any ideas?
a
I don't know gradle very well, but the lines you show does not look like plugin declaration, as shown in kotlin serialization doc: https://github.com/Kotlin/kotlinx.serialization#gradle
m
@Alexis Manin if Gradle part was a problem then it would probably throw a build error. What's even weirder - the serialization works and I guess it's an issue with IntelliJ
a
I am with @Alexis Manin on this one, if its okay with you, please post your whole build.gradle.kt
o
The top lines of your build.gradle.kts should look like this:
Copy code
plugins {
    kotlin("multiplatform") version "1.4.32"
    kotlin("plugin.serialization") version "1.4.32"
    application
}
If not, there is no plugin generating serializers as indicated in the error message you were getting.
m
Yes, I have that part in my modules build.gradle.kts What's strange is that IntelliJ is showing the warning, but the app runs without troubles and data gets serialized/deserialized properly
a
IntelliJ is often a bit fussy with gradle builds. What version of gradle are you using? Do you have the gradle wrapper set up? Is IntelliJ configured to use the gradle from your
gradle/gradle-wrapper.properties
file? Do you have nested modules/projects using either
include(...)
or
includeBuild(...)
? Are you using
buildSrc
for managing build logic? I have found that IntelliJ is easily confused by these constructs.
m
@adk yes, I have gradle wrapper, version gradle-6.8.2 and Intellij is using the wrapper. Not using buildSrc, nor includeBuild and include in settings.gradle.kts only the modules generated by wizard
m
I am having the same issue for weeks now! did you find any solution for it @Marc Knaup?
m
@Mouaad me? 🤔
m
@Mouaad no I haven't. I simply got used to the warning and kept on going 😄
a
Hmmm, looks like this is probably a bug. I just created a new minimal project from scratch and set up serialization and I also get a warning in IntelliJ - although serialization works fine. Oddly, if I move the
@Serializable
class from
commonMain
to
commonTest
, the warning goes away.
🐛 3
m
Yeah. I moved my class from common to jvm module and also this made the warning go away
m
Sorry I tagged the wrong person 😄 Yes, I am having the same issue on different computers! so annoying 😕
_Update_: using kotlin 1.5.0 fixed the issue for me!!