live-plugin
live-plugin copied to clipboard
Grab external dependency for plugin
I would like to use external library in my plugin, for example the http-builder:
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
However, it seems that live-plugin doesn't support this -> I get the following error:
Couldn't load plugin: "msf-plugin". Error linking script. org/apache/ivy/core/settings/IvySettings
If I remove the @Grab
annotation and add the http-builder jar directly to module dependencies then syntax errors in editor are gone (IDEA is able to resolve dependency) but the plugin run still fails:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:file:/Users/jumar/Library/Application%20Support/IntelliJIdea13/live-plugins/msf-plugin/plugin.groovy: 5: unable to resolve class groovyx.net.http.RESTClient @ line 5, column 1. import groovyx.net.http.RESTClient ^file:/Users/jumar/Library/Application%20Support/IntelliJIdea13/live-plugins/msf-plugin/plugin.groovy: 6: unable to resolve class groovyx.net.http.ContentType @ line 6, column 1. import static groovyx.net.http.ContentType.* ^file:/Users/jumar/Library/Application%20Support/IntelliJIdea13/live-plugins/msf-plugin/plugin.groovy: 6: unable to resolve class groovyx.net.http.ContentType @ line 6, column 1. import static groovyx.net.http.ContentType.* ^3 errors
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:309)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:927)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:574)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:523)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:279)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:258)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.doParseClass(GroovyScriptEngine.java:254)
at groovy.util.GroovyScriptEngine$ScriptClassLoader.parseClass(GroovyScriptEngine.java:236)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:244)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:202)
at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:521)
at liveplugin.pluginrunner.GroovyPluginRunner.runGroovyScript(GroovyPluginRunner.java:79)
at liveplugin.pluginrunner.GroovyPluginRunner.runPlugin(GroovyPluginRunner.java:53)
at liveplugin.pluginrunner.RunPluginAction$2.run(RunPluginAction.java:107)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:680)
Is there any option how to use external libraries?
Ok, I was able to leverage // add-to-classpath
as demonstrated in https://github.com/dkandalov/live-plugin/blob/master/plugin_examples/liveplugin/pluginexamples/classpathExample/plugin.groovy.
However, it would be nice to have a support for @Grab
and transitive dependencies in particular.
I ended up with something like this in my plugin.groovy:
// add-to-classpath /opt/lib/groovy/httpbuilder/http-builder-0.7.1.jar
// add-to-classpath $HOME/.m2/repository/org/apache/httpcomponents/httpclient/4.2.1/httpclient-4.2.1.jar
// add-to-classpath $HOME/.m2/repository/xml-resolver/xml-resolver/1.2/xml-resolver-1.2.jar
// add-to-classpath $HOME/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar