LinkageError related to Scala collections after upgrade to 2019.2
I am working on custom plugin which depends on Scala and Bazel plugins. After upgrade to 2019.2, I have LinkageError in my plugin (package com.wixpress.labeldex.annotation is from my plugin):
```
2019-09-04 11:36:21,925 [ 412797] ERROR - aemon.impl.PassExecutorService - loader constraint violation: when resolving interface method "org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt.importExprs()Lscala/collection/Seq;" the class loader (instance of com/intellij/ide/plugins/cl/PluginClassLoader) of the current class, com/wixpress/labeldex/annotation/ImportStatements$, and the class loader (instance of com/intellij/ide/plugins/cl/PluginClassLoader) for the method's defining class, org/jetbrains/plugins/scala/lang/psi/api/toplevel/imports/ScImportStmt, have different Class objects for the type scala/collection/Seq used in the signature
java.lang.LinkageError: loader constraint violation: when resolving interface method "org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.ScImportStmt.importExprs()Lscala/collection/Seq;" the class loader (instance of com/intellij/ide/plugins/cl/PluginClassLoader) of the current class, com/wixpress/labeldex/annotation/ImportStatements$, and the class loader (instance of com/intellij/ide/plugins/cl/PluginClassLoader) for the method's defining class, org/jetbrains/plugins/scala/lang/psi/api/toplevel/imports/ScImportStmt, have different Class objects for the type scala/collection/Seq used in the signature
at com.wixpress.labeldex.annotation.ImportStatements$.isResolved(ImportStatements.scala:11)
at com.wixpress.labeldex.annotation.ImportStatements.isResolved(ImportStatements.scala)
at com.wixpress.labeldex.annotation.ScalaImportStatementsAnnotator.annotate(ScalaImportStatementsAnnotator.java:22)
at com.intellij.codeInsight.daemon.impl.DefaultHighlightVisitor.runAnnotators(DefaultHighlightVisitor.java:121)
```
In my code I have a code which uses classes (org.jetbrains.plugins.scala.lang.psi.api.toplevel.imports.{ScImportExpr, ScImportStmt}) from Scala plugin.
Plugin build file:
plugins {
id 'org.jetbrains.intellij' version '0.4.10'
id 'scala'
}
intellij {
version '2019.2.1'
plugins 'org.intellij.scala:2019.2.15', 'com.google.idea.bazel.ijwb:2019.08.19.0.5', 'java'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.scala-lang:scala-library:2.12.7'
compile('org.scala-lang.modules:scala-java8-compat_2.12:0.9.0') {
transitive = false
}
compile group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2'
}
patchPluginXml {
sinceBuild 192.5728
}
// disabled, because stopped working in 192
buildSearchableOptions.enabled = false
group 'com.wixpress'
version project.property("plugin.version")
runIde { jbrVersion 'jbrex8u152b1343.26' }
I would appreciate any advice!
请先登录再写评论。
scala-library should be excluded from your plugin's runtime classpath since it already depends on another plugin(Scala plugin for IJ) which already has one.
If you don't do this, instances of scala-library classes such as Seq will be unusable when passed across classloaders(between different plugin with Scala).
There's an in-progress issue in sbt-idea-plugin which should resolve this problem: https://github.com/JetBrains/sbt-idea-plugin/issues/11
Thank you, this seems to solve the problem.
The
LinkageError
you're encountering is due to conflicting Scala versions between your plugin and the Scala plugin bundled with IntelliJ 2019.2. The Scala plugin includes its own Scala library (likely 2.12.x), and bundling your own (scala-library:2.12.7
) causesClassLoader
issues. To fix this, remove the Scala library from your dependencies and instead mark the Scala plugin asoptional false
in theintellij.plugins
block to ensure proper class loading. Avoid shading or repackaging Scala classes. Keep all plugins and dependencies aligned with the IDE's Scala plugin version to prevent classpath conflicts.