Plugins should be able to depend on third party libraries #105
Description
Description
Currently plugins can't have dependencies on other libraries. When added to their build.sbt
file they compile fine and IntelliJ auto-completion works. But when they get run and try to use a class from their dependencies they throw a java.lang.NoClassDefFoundError
. It's not working because we use the package
sbt task which only adds the class files generated from the local sources to the jar file, but doesn't include the class files from the dependencies.
According to the wiki plugins should be able to have dependencies:
https://github.com/codeoverflow-org/chatoverflow-wiki/blob/dd7688339a33fd0f114512e63f4d6d00255bc94e/development/Writing-a-plugin.md (end of the first paragraph of the "Create a new plugin project" section)
Some ideas for a solution
A solution to this is to use the assembly
task that is added by sbt/sbt-assembly. However the assembly
task currently fails while packaging the framework because some files are provided by 2 or more libraries. We either need to get the assembly
task on the framework working or we need a custom task that only executes assembly
in the plugin sbt projects, but I currently don't know how such thing could be done. I think that it is doable though.
This solution has some disadvantages. First if each plugin has a copy of the library in its jar and 10 plugins use the same dependency we have a really inefficient use of storage.
The second problem is that I don't know if the JVM is smart enough to check that those 10 copies of the library are the same and only keep one copy in memory or if it will then keep all 10 version of the library in memory. This might really become a problem with a huge count of running plugins on a low-memory-environment like a Rasperry Pi 3 which only has 1 GB of RAM and already looses at least 200-300 MB to the operating system and JVM. In my testing I had arround 430 MB of used memory with no running plugins or connectors, but I also had containerd and a k3s node with some pods running meaning I wouldn't take this number serious at all.
Another idea I had is to add a xml file containing all dependencies into the plugin jar and then download them at runtime using lets say coursier. This would allow for sharing the downloaded dependencies between plugins which drastically decreases storage needs, but I think this is a really big overkill for what we are trying to achieve.
I'm open for any thoughts/ideas on this.