Exposing API for other plugins that use optional depends
I want to set up a @Service (let's say Application level) that provides an interface to other plugin authors can call from their plugins. So for example, if my plugin is com.foo, I want it to expose a @Service called MyAppService so that other plugins can request it *if* my plugin is installed.
So I understand that “optional” can be specified from another plugin, call it com.bar in its plugin.xml/depends. But I'm having trouble figuring out exact how to set this up for development. And I understand that lightweight plugins will be found simply on a scan for the @Service annotation and I shouldn't need to expose the service separately in plugin.xml for com.foo.
Specifically:
- how do I “publish” com.foo so that from plugin.xml, build.gradle.kts and anywhere else the plugin needs to be referenced by com.bar, it is “visible”? Is there a local repo like maven would use to publish working build SNAPSHOTs of com.foo?
- how does “MyAppService” get on the runtime classpath for com.bar? Does it get added automatically when I successfully make the plugin dependency and publish my plugin (com.foo)?
- is there a template or best practice for how I could build from com.foo and com.bar in tandem so that I could make could changes to com.foo, rebuild, then rebuild com.bar and test my changes in to com.foo in com.bar?
Please sign in to leave a comment.
There's nothing special in packaging or deployment. The service (technically all your plugin classes) will be made visible/accessible for other dependent plugins. Please note that you must maintain compatibility for exposed API, as it is not possible require a specific version when depending on other plugins.
You may also want to publish your plugin API sources https://plugins.jetbrains.com/docs/intellij/bundling-plugin-openapi-sources.html