How does the integration between IntelliJ and Kotlin compiler plugins work? I use a non-standard (well, non-Gradle) build for my Kotlin code, and I get errors all over the place because the IDE can’t resolve the generated Type.serializer()
methods. I have the serialization compiler plugin configured, both in my build and in the Kotlin Compiler settings in the IDE. The code compiles and runs fine both when built in the IDE and when run via the code compiled by my build, but the IDE just isn’t aware that the plugin has been applied. How does this work for Gradle? I had similar problems with Maven, it’s not just really esoteric builds which suffer from this. Is there a way I can configure this?
Hi! Can’t it be the case that you apply k1 compiler plugin to IJ which uses k2 compiler?
I don’t think so, I’m using org.jetbrains.kotlin/kotlin-serialization-compiler-plugin:2.1.10
in my build, and I have -Xplugin=/Users/colin/.m2/repository/org/jetbrains/kotlin/kotlin-serialization-compiler-plugin/2.1.10/kotlin-serialization-compiler-plugin-2.1.10.jar
specified in my Settings | Build, Execution, Deployment | Compiler | Kotlin Compiler | Additional command line parameters.
Hi Colin!
I would like to ask two questions:
- Do you use K1 Mode or K2 Mode for Kotlin IntelliJ Plugin? You can see this info in the “About” section of IntelliJ IDEA
- Would it be possible for you to send us a reproducer project?
I’m using K2 mode. I’ll get a repro project together and share it.
Here’s a repro project: GitHub - cmf/serialization-repro.
main.kt
has a slightly modified version of the example from the serialization repo homepage. Notice that Project.serializer()
cannot be resolved by the IDE, but the code compiles and runs fine.
I have the Kotlin compiler setting described above, but you’ll need to update that with the path to your own .m2
repo.
I could not reproduce your problem locally, but I have a fresh nightly version of IDEA
Could you please provide details about your IDEA version?
Also, I am not sure if a Maven project is a good reproducer for your problem, because Maven (similarly to Gradle) actually sets up the serialization plugin for you, so you won’t have to manually specify anything in the compiler arguments.
See this part of the pom.xml
:
<configuration>
<compilerPlugins>
<plugin>kotlinx-serialization</plugin>
</compilerPlugins>
</configuration>
Maybe you could try to do a JPS-based reproducer?
Thanks for the help with this. Here’s my config:
IntelliJ IDEA 2024.3.3 (Ultimate Edition)
Build #IU-243.24978.46, built on February 12, 2025
Licensed to Colin Fleming
You have a perpetual fallback license for this version.
Subscription is active until January 12, 2026.
Runtime version: 21.0.6+8-b631.39 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.3.1
Kotlin plugin: K2 mode
Kotlin analyzer version: 2.1.20-ij243-51
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 8192M
Cores: 10
Metal Rendering is ON
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
Non-Bundled Plugins:
com.intellij.notebooks.core (243.23654.153)
org.antlr.intellij.plugin (1.24)
PythonCore (243.24978.46)
DevKit (243.24978.46)
com.cursive-ide.cursive-dev (1.0-SNAPSHOT)
com.intellij.uiDesigner (243.23654.189)
com.devoxx.genie (0.4.16)
Pythonid (243.24978.46)
intellij.jupyter (243.23654.117)
org.jetbrains.plugins.kotlin.jupyter (243.23654.153)
org.jetbrains.android (243.24978.46)
Dart (243.23654.44)
com.github.bjansen.intellij.pebble (v0.11.0)
io.flutter (83.0.4)
com.intellij.mcpServer (1.0.15)
com.cursiveclojure.cursive (1.14.1-dev3-2024.3)
nz.ideogram.scribe (replaced during build process)
Kotlin: 243.24978.46-IJ
I’ll try to set up a project more like my actual project tomorrow.
Interestingly, the Maven repro works for me with the latest 2025.1 EAP. However, my own project does not. I’ll share a repo tomorrow.
I’m curious, how does this actually work? Is there a general mechanism for supporting code generated by Kotlin Compiler plugins, or is serialization special cased in IntelliJ? If so, what is required to trigger the resolution?
Here’s a repro project just using IntelliJ’s compiler: GitHub - cmf/serialization-repro2. As before, it compiles and runs but the IDE cannot resolve the serializer functions:
This is true even with the latest 2025.1 EAP:
IntelliJ IDEA 2025.1 EAP (Ultimate Edition)
Build #IU-251.21418.62, built on February 18, 2025
Source revision: 164366bb6ace6
Licensed to IntelliJ IDEA EAP user: Colin Fleming
Expiration date: March 20, 2025
Runtime version: 21.0.6+8-b872.85 aarch64 (JCEF 122.1.9)
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Toolkit: sun.lwawt.macosx.LWCToolkit
macOS 15.3.1
Kotlin plugin: K2 mode
Kotlin analyzer version: 2.2.0-dev-3086
GC: G1 Young Generation, G1 Concurrent GC, G1 Old Generation
Memory: 8192M
Cores: 10
Metal Rendering is ON
Registry:
debugger.new.tool.window.layout=true
ide.experimental.ui=true
jvm.dfa.analysis.ui.security.analysis.window.was.shown=true
Non-Bundled Plugins:
org.antlr.intellij.plugin (1.24)
PythonCore (251.21418.62)
DevKit (251.21418.62)
com.cursive-ide.cursive-dev (1.0-SNAPSHOT)
com.intellij.uiDesigner (251.21418.62)
com.devoxx.genie (0.4.16)
Pythonid (251.21418.62)
org.jetbrains.plugins.gitlab (243.21565.204)
org.jetbrains.plugins.github (243.21565.204-ultimate)
com.github.bjansen.intellij.pebble (v0.11.0)
com.intellij.mcpServer (1.0.15)
org.jetbrains.bsp (2025.1.0)
org.jetbrains.bazel (2025.1.0)
com.cursiveclojure.cursive (1.14.1-eap2-2025.1)
nz.ideogram.scribe (replaced during build process)
org.intellij.scala (2025.1.6)
Kotlin: 251.21418.62-IJ
I just tried this with EAP6 since it talks about improvements in this area, but it still fails there.
Hi @roman.golyshev, have you had a chance to look at this? Is there any more information I can provide?
Thank you for the second reproducer, Colin, I was able to reproduce the problem there
Will get back to you if I manage to discover anything
Hi again!
I believe that the issue here is that you do not have a Kotlin Facet applied to your module, and without it the configured compiler plugins are not picked
Can you please try to add the default Kotlin Facet to your module and see if it helps?
Hi Roman, fantastic! That does indeed fix the problem, thank you! I’ll have to modify my build to add Kotlin facets as required during project sync.