using classes of dependency plugin transitive library : java.lang.LinkageError: #107
-
There is a sample intellij plugin that depends on org.intellij.scala plugin also. For parsing json in scala, there are multiple libraries, and we decided to use spray json library. Reason for choosing spray json :- spray json library is present in library dependency graph of org.intellij.scala, and sample intellij plugin directly depends on org.intellij.scala plugin. So to keep sample intellij plugin library size minimum, we thought of using json parser library that is used by org.intellij.scala plugin. But, we are getting PluginClassLoader exception :-
Our understanding so far for this exception :- As org.intellij.scala and sample intellij are loaded in different classloaders, so sample intellij plugin can't use any class loaded by PluginClassLoader of org.intellij.scala. Adding spray json to libraryDependencies in sample intellij plugin will solve the class-loader issue, but increase the packaged plugin binary size, as spray json library is also packaged in sample intellij plugin. plugin.xml
build.sbt :
plugins.sbt
Summary: if spray-json is not present in SamplePlugin/target/plugin/logicIj/lib, then plugin is giving LinkageError, when run from intellij-run configuration or by loading sample plugin zip in fresh intellij instance. Kindly confirm, if our understanding is correct and please suggest recommended approach/ best practices for this scenario. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 6 replies
-
I've created the dummy plugin via IntelliJ Platform plugin template println(new spray.json.JsString("{}")) Here is an example classloader for a simple action.
If you do not create any clasloaders explicitly and if your plugin's code is run in IDEA process you should be able to use the classes from Scala plugin, and the classes it depends on. Here is full import org.jetbrains.sbtidea.Keys._
lazy val testIntellij2 =
project.in(file("."))
.enablePlugins(SbtIdeaPlugin)
.settings(
version := "0.0.1-SNAPSHOT",
scalaVersion := "2.13.2",
ThisBuild / intellijPluginName := "TestIntellij2",
ThisBuild / intellijBuild := "211.7142.45",
ThisBuild / intellijPlatform := IntelliJPlatform.IdeaCommunity,
Global / intellijAttachSources := true,
Compile / javacOptions ++= "--release" :: "11" :: Nil,
intellijPlugins += "com.intellij.properties".toPlugin,
unmanagedResourceDirectories in Compile += baseDirectory.value / "resources",
unmanagedResourceDirectories in Test += baseDirectory.value / "testResources",
intellijPlugins += "org.intellij.scala:2021.1.18".toPlugin,
intellijDownloadSources := true,
ThisBuild / bundleScalaLibrary := false,
) and <idea-plugin>
<id>naumneko.test.vendor.testintellij2</id>
<name>TestIntellij2</name>
<version>0.0.1-SNAPSHOT</version>
<vendor>naumneko.test.vendor</vendor>
<description>A new plugin for IntelliJ platform written in Scala and built with SBT</description>
<idea-version since-build="211.0"/>
<depends>com.intellij.modules.platform</depends>
<depends>com.intellij.properties</depends>
<depends>org.intellij.scala</depends>
<!-- SOME ACTIONS, LISTENERS, etc... -->
</idea-plugin>
|
Beta Was this translation helpful? Give feedback.
-
@moglideveloper |
Beta Was this translation helpful? Give feedback.
-
@moglideveloper is |
Beta Was this translation helpful? Give feedback.
-
@mutcianm |
Beta Was this translation helpful? Give feedback.
-
The classloading constraint violation is caused by the scala-library that gets loaded in both parent(Scala plugin) and child(this plugin) classloaders. |
Beta Was this translation helpful? Give feedback.
-
Please try with sbt-idea-plugin version 3.12.4 |
Beta Was this translation helpful? Give feedback.
Please try with sbt-idea-plugin version 3.12.4