Cannot cast JpsJavaModelSerializerExtension to JpsModelSerializerExtension


Hi all,

The actual error is a bit too long for the subject: 

Cannot cast to org.jetbrains.jps.model.serialization.JpsModelSerializerExtension

I'm trying to write compiler extension but run into this weird classloading related issue. I suppose the two JpsModelSerializerExtension classes got loaded by different classloaders and therefore are not the same causing the cast to fail. But why this happens so deep inside IJ is too difficult for me.

My plugin.xml boils down to the snippet below. I had to add <depends></depends> otherise the CompileServerPlugin was not found.

I wonder now whether this issue I reported here :  Unfortunately unanswered so far.The Gradle build puts many jars including the jps-model-*.jar files (and maven aether-*.jar libs too!) in the lib dir of the plugin. I would think this is not needed. But this could explain why the JpsModelSerializerExtension class get loaded again.



ps: at the risk of sounding negative - this recommended Gradle based plugin creation is not a great experience so far. The DevKit way, a few years ago, was a bit smoother.


<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
<compileServer.plugin classpath="exceptional-1.0-SNAPSHOT.jar;exceptional-jps-plugin-1.0-20200818.173223-1.jar" />





I've answered in your previous post why your artifact gets so fat - to quickly summarize it: you are using SDK 2020.2 (which is 193.6911.18) and explicitly add the JPS jar (which is already bundled in the SDK's Java module). Having JPS in two versions makes Gradle bundle the second one into the artifact.

That makes your zip fat and leads to the current issue: in the runtime, some classes (JpsJavaModelSerializerExtension) are taken from the SDK and another (JpsModelSerializerExtension) from external JPS jar. Because of the version's incompatibility, it's not possible to cast one to another.

Please use the solution suggested in the another post - remove the com.jetbrains.intellij.platform:jps-build:193.5964 dependency and provide a dependency to java plugin in the Gradle intellij configuration:

intellij {
  version = '2020.1'
  plugins = ['java']

Also it's necessary to add:


in the plugin.xml file as described in Modules Specific to Functionality docs page.


Thank you very very much Jakub! I in turn apologize for my late reply

I really did not understand that the 'intellij' task adds all the necessary dependencies.

Best regards,



Please sign in to leave a comment.