<@U53QPGS1Z> dsl-lib-support.jar is it included in...
# scripting
i
@gammanik dsl-lib-support.jar is it included in your plugin?
g
yes. It’s in a separate module. I’m using Multi-project build. Do you think switching to composite build could help?
i
You could load dsl-lib-supprt.jar from the plugin directory where it's installed
Copy code
val myIdeaPluginLibPath = toSystemIndependentName(getPluginsPath() + "/my-idea-plugin-name/lib/dsl-lib-supprt.jar")
g
I’m loading it from my module’s build folder inside my plugin:
Copy code
File("/Users/Nikita/Documents/lib-support/dsl-lib-support/build/libs/dsl-lib-support.jar")
Because I want every project using my plugin to be able to use my dsl rules for kotlin scripting. The path is ok and the script can see the dsl-rule classes. I guess the problem is that
ClassLoader
is different.
I actually found the same question Trying to apply it for my case yet with no luck.
image.png
i
When you run the plugin it will copy all the lib to one directory, and it's different from the build directory, you can get the directory with getPluginsPath() + "/my-idea-plugin-name/lib/"
the idea is to add the same jar used by the plugin to the scriptengine classpath
g
Thanks for your advice! Unfortunately it wasn’t enough. As I found later I’ve been loading my jar with
thread.contextClassLoader
which is
UrlClassLoader
but all of plugins classes are loaded with
PluginClassLoader
(which is a inherited from
UrlClassLoader
) So I manually set:
Copy code
Thread.currentThread().contextClassLoader = this.javaClass.classLoader
And it accidentally solved the problem. That what the error message was about:
Copy code
java.lang.ClassCastException: class MethodToMark cannot be cast to class MethodToMark (MethodToMark is in unnamed module of loader <http://java.net|java.net>.URLClassLoader @67d327ab; MethodToMark is in unnamed module of loader <http://com.intellij.ide.plugins.cl|com.intellij.ide.plugins.cl>.PluginClassLoader @66867586)