I’m curious about the possibility of publishing two separate plugins on the marketplace. One plugin would include the core rule evaluation engine, along with a couple of basic rules. The other plugin would contain a set of publicly available rules.
I would appreciate any feedback or advice from anyone who has attempted a similar approach or has suggestions on how to proceed. It’s important to know if this approach is allowed before making any changes to the repositories.
For more context, the core plugin I am referring to is a plugin designed to evaluate OpenAPI/Swagger definitions, which can be found at https://github.com/apiaddicts/sonar-openapi. The basic public set of rules can be found at https://github.com/apiaddicts/dosonarapi. While the core plugin is required, users can choose whether to install the public rules or develop their own rules based on the public rules or from scratch.
Yes, this is possible. This is the architecture we use when our analyzers support custom rules.
See for example our sample plugin for Java custom rules.
By default, each plugin runs in an isolated classloader. The trick is to have your main plugin put all classes that should be “visible” by other plugins in the package
org.sonar.plugins.<pluginKey>.api. By convention, this package will be “exported” to all other plugins.
Then “secondary” plugins usually have to register themselves on the main plugin. The way we follow is to use our IoC container in a similar way to the ServiceProvider framework in Java.
The main plugin will expose an interface, for example,
org.sonar.plugins.pluginA.api.CustomCheck. Example: CheckRegistrar
Each secondary plugin will implement this interface, and add the class to the IoC container.
Then the main plugin can “query” all implementations at runtime using constructor injection.
For a better user experience, it is recommended to have your secondary plugins declare a dependency on the main plugin in its MANIFEST.
Hope that help!
Thank for the examples that you provided. Now we have a clear path to follow.