Include jar with plugin
已回答
What is the best way to include a dependency with a plugin?
Either
1) Have that dependency be shaded into the plugin jar
2) Have the plugin download the dependency and store it somewhere.
请先登录再写评论。
The most efficient way to work with the external libraries is to use Gradle/Maven and define the proper dependency.
In case, your dependency is provided as a .jar, which has to be delivered with your plugin - put it into some libs/ directory and specify it as a library: How to add local .jar file dependency to build.gradle file?
In case, such jar is optional for your plugin - so it's not a core feature and its size is significant, you can implement a mechanism that downloads it in the runtime. Such a problem was described also in the following issue asciidoctor-intellij-plugin / Move extra functionality to separate download.
Thanks for the reply.
Will dependencies added to /libs be included in the distribution .zip ?
Yes, they'll be added to the libs directory in your .zip archive.
Thanks again, and final follow up question.
Inside a RunnableState, how would I get those libs onto the classpath? Would something like this seem correct:
override fun configureRTClasspath(javaParameters: JavaParameters, module: Module?) {javaParameters.classPath.addFirst(PathUtil.getJarPathForClass(Class.forName("com.myclass.Class")))
}
Jars will be added to your zip archive only in case it is already referred in your Gradle configuration file as a dependency. With that, it already should be available in your classpath.
Sorry, I don't think I was very clear in my original question. The dependency is not for the plugin itself, but the plugin launches a process and this dependency needs be on the classpath of the launched process.
I've added the dependency to gradle here: https://github.com/kotest/kotest-intellij-plugin/blob/master/build.gradle#L34
And then when I launch the process I add that dependency to the runtime classspath here:
https://github.com/kotest/kotest-intellij-plugin/blob/master/src/main/kotlin/io/kotest/plugin/intellij/KotestRunnableState.kt#L46-L48
It works, I just wanted to check that this is the right way to do it.
Ah, sorry I didn't catch it.
Regarding your question - yes, that way of adding the dependencies is correct.
Great thank you. I appreciate the responses.
Hi all, sorry for postpone question but your link now has 404 status. I am right understood that your use gradle dependency scope as - runtimeOnly(fileTree("libs") { include("*.jar") }) ?