Package org.sonar.api

Interface Plugin

  • All Known Implementing Classes:

    public interface Plugin
    Entry-point for plugins to inject extensions into SonarQube.

    The JAR manifest must declare the name of the implementation class in the property Plugin-Class. This property is automatically set by sonar-packaging-maven-plugin when building plugin.

    Example of implementation

     public class MyPlugin implements Plugin {
       public void define(Context context) {
         context.addExtensions(MySensor.class, MyRules.class);
         if (context.getSonarQubeVersion().isGreaterThanOrEqual(Version.create(6, 0))) {
           // Extension which supports only versions 6.0 and greater
           // See org.sonar.api.SonarRuntime for more details.

    Example of pom.xml


    Example of Test Add a test dependency to sonar-plugin-api-impl to have access to implementation classes in tests.

     public void test_plugin_extensions_compatible_with_5_6() {
       SonarRuntime runtime = SonarRuntimeImpl.forSonarQube(Version.create(5, 6), SonarQubeSide.SCANNER);
       Plugin.Context context = new PluginContextImpl.Builder().setSonarRuntime(runtime).build();
       MyPlugin underTest = new MyPlugin();
    See Also:
    for unit tests
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static class  Plugin.Context  
    • Method Detail

      • define

        void define​(Plugin.Context context)
        This method is executed at runtime when:
        • Web Server starts
        • Compute Engine starts
        • Scanner starts