This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

See latest version
Start Free
10.4 | Extension Guide | Developing a plugin | Plugin basics

Was this page helpful?

Plugin basics

On this page

Building your plugin


To build a plugin, you need Java 8 and Maven 3.1 (or greater). Gradle can also be used thanks to the gradle-sonar-packaging-plugin (note that this plugin is not officially supported by SonarSource).

Sonar Plugin API

The sonar-plugin-api is a Java API that is used to develop plugins.

Create a Maven project

The recommended way to start is by duplicating the plugin example project:

If you want to start the project from scratch, use the following Maven pom.xml template:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <!-- it's recommended to follow the pattern "sonar-{key}-plugin", for example "sonar-myphp-plugin" -->
  <!-- this is important for sonar-packaging-maven-plugin -->
      <!-- groupId has changed to 'org.sonarsource.api.plugin' starting on version 9.5 -->
      <!-- minimal version of SonarQube to support. -->
      <!-- mandatory scope -->
          <!-- the entry-point class that extends org.sonar.api.SonarPlugin -->
          <!-- advanced properties can be set here. See paragraph "Advanced Build Properties". -->


To build your plugin project, execute this command from the project root directory:

mvn clean package

The plugin jar file is generated in the project's target/ directory.


"Cold" Deploy
The standard way to install the plugin for regular users is to copy the jar artifact, from the target/ directory to the extensions/plugins/ directory of your SonarQube installation, then start the server. The file logs/web.log will then contain a log line similar to:
Deploy plugin Example Plugin / 0.1-SNAPSHOT
Scanner extensions such as sensors are immediately retrieved and loaded when scanning source code.


Debugging web server extensions

  1. Edit conf/ and set: sonar.web.javaAdditionalOpts=-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000.
  2. Install your plugin by copying its jar file to extensions/plugins.
  3. Start the server. The line Listening for transport dt_socket at address: 5005 is logged in logs/sonar.log.
  4. Attach your IDE to the debug process (listening on port 8000 in the example).

Debugging compute engine extensions
Same procedure as for web server extensions (see above), but with the following property:


Debugging scanner extensions

$ export SONAR_SCANNER_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=8000"
$ cd /path/to/project
$ sonar-scanner

When using the Scanner for Maven, then simply execute:

$ cd /path/to/project
$ mvnDebug sonar:sonar

Advanced build properties

Plugin properties are defined in the file META-INF/MANIFEST.MF of the plugin jar file.

Most of them are defined through the <configuration> section of the sonar-packaging-maven-plugin. Some are taken from standard pom nodes Effective values are listed at the end of the build log:

[INFO] --- sonar-packaging-maven-plugin:1.15:sonar-plugin (default-sonar-plugin) @ sonar-widget-lab-plugin ---
[INFO] -------------------------------------------------------
[INFO] Plugin definition in Marketplace
[INFO]     Key: widgetlab
[INFO]     Name: Widget Lab
[INFO]     Description: Additional widgets
[INFO]     Version: 1.9-SNAPSHOT
[INFO]     Entry-point Class: org.codehaus.sonar.plugins.widgetlab.WidgetLabPlugin
[INFO]     Required Plugins:
[INFO]     Use Child-first ClassLoader: false
[INFO]     Base Plugin:
[INFO]     Homepage URL:
[INFO]     Minimal SonarQube Version: 4.5.1
[INFO]     Licensing: GNU LGPL 3
[INFO]     Organization: Shaw Industries
[INFO]     Organization URL:
[INFO]     Terms and Conditions:
[INFO]     Issue Tracker URL:
[INFO]     Build date: 2015-12-15T18:28:54+0100
[INFO]     Sources URL:
[INFO]     Developers: G. Ann Campbell,Patroklos Papapetrou
[INFO] -------------------------------------------------------
[INFO] Building jar: /dev/sonar-widget-lab/target/sonar-widget-lab-plugin-1.9-SNAPSHOT.jar

Supported standard pom node properties:

Maven propertyManifest keyNotes
versionPlugin-Version(required) Plugin version as displayed in page "Marketplace". Default: ${project.version}
pluginApiMinVersionSonar-VersionMinimal version of supported Sonar Plugin API at runtime. For example, if the value is, then deploying the plugin on SonarQube versions with sonar-plugin-api (ie. SonarQube 9.5) and lower will fail. The default value is given by the version of sonar-plugin-api dependency. It can be overridden with the Maven property pluginApiMinVersion (since sonar-packaging-maven-plugin 1.22). That allows in some cases to use new features of recent API and to still be compatible at runtime with older versions of SonarQube. Default: version of dependency sonar-plugin-api
licensePlugin-LicensePlugin license as displayed on page "Marketplace". Default ${project.licenses}
developersPlugin-DevelopersA list of developers is displayed on the page "Marketplace". Default: ${project.developers}

Supported <configuration> properties:

Maven propertyManifest keyNotes
pluginKeyPlugin-Key(required) Contains only letters/digits and is unique among all plugins. Examples: groovy, widgetlab. Constructed from ${project.artifactId}. Given an artifactId of: sonar-widget-lab-plugin, your pluginKey will be: widgetlab
pluginClassPlugin-Class(required) Name of the entry-point class that extends org.sonar.api.SonarPlugin. Example: org.codehaus.sonar.plugins.widgetlab.WidgetLabPlugin
pluginNamePlugin-Name(required) Displayed in the page "Marketplace". Default: ${}
pluginDescriptionPlugin-DescriptionDisplayed in the page "Marketplace". Default: ${project.description}
pluginUrlPlugin-HomepageHomepage of website, for example${project.url}
pluginIssueTrackerUrlPlugin-IssueTrackerUrlExample: Default: ${project.issueManagement.url}
pluginTermsConditionsUrlPlugin-TermsConditionsUrlUsers must read this document when installing the plugin from Marketplace. Default: ${sonar.pluginTermsConditionsUrl}
useChildFirstClassLoaderPlugin-ChildFirstClassLoaderEach plugin is executed in an isolated classloader, which inherits a shared classloader that contains API and some other classes. By default the loading strategy of classes is parent-first (look up in shared classloader then in plugin classloader). If the property is true, then the strategy is child-first. This property is mainly used when building plugin against API < 5.2, as the shared classloader contained many 3rd party libraries (guava 10, commons-lang, ...) false.
basePluginPlugin-BaseIf specified, then the plugin is executed in the same classloader as basePlugin.
pluginSourcesUrlPlugin-SourcesUrlURL of SCM repository for open-source plugins. Displayed on page "Marketplace". Default: ${project.scm.url}
pluginOrganizationNamePlugin-OrganizationThe organization which develops the plugin is displayed on the page "Marketplace". Default: ${}
pluginOrganizationUrlPlugin-OrganizationUrlURL of the organization, displayed on the page "Marketplace". Default: ${project.organization.url}
sonarLintSupportedSonarLint-SupportedWhether the language plugin supports SonarLint or not. Only SonarSource analyzers and custom rules plugins for SonarSource analyzers should set this to true.
pluginDisplayVersionPlugin-Display-VersionThe version is displayed in SonarQube administration console. By default it's the raw version, for example, "1.2", but can be overridden to "1.2 (build 12345)" for instance. Supported in sonar-packaging-maven-plugin Default: ${project.version}

Languages for which this plugin should be downloaded. Use to make sure dependency errors are avoided when the loading of analyzers is optimized. This property must be added to the <configuration> section of the plugin’s pom.xml file.

For an example, see the Custom Rules section of the Java page.

The Maven sonar-packaging-maven-plugin supports also these properties:

Maven propertyManifest keyNotes
addMavenDescriptorCopy pom file inside the directory META-INF of generated jar file?Boolean. Default: ${sonar.addMavenDescriptor} / true.
skipDependenciesPackagingDo not copy Maven dependencies into jar file.Default: ${sonar.skipDependenciesPackaging} /false`.

Other Manifest fields:

  • Implementation-Build: Identifier of build or commit, for example, the Git SHA1. 94638028f0099de59f769cdca776e506684235d6. It is displayed for debugging purposes in logs when the SonarQube server starts.

API basics

Extension points

SonarQube provides extension points for its three technical stacks:

  • Scanner, which runs the source code analysis.
  • Compute Engine, which consolidates the output of scanners, for example by:
    • computing 2nd-level measures such as ratings.
    • aggregating measures (for example number of lines of code of project = sum of lines of code of all files).
    • assigning new issues to developers.
    • persisting everything in data stores.
  • Web application.

Extension points are not designed to add new features but to complete existing features. Technically they are contracts defined by a Java interface or an abstract class annotated with @ExtensionPoint. The exhaustive list of extension points is available in the Javadoc.

The implementations of extension points (named extensions) provided by a plugin must be declared in its entry point class, which implements org.sonar.api.Plugin and which is referenced in the pom.xml:

package org.sonarqube.plugins.example;
import org.sonar.api.Plugin;
public class ExamplePlugin implements Plugin {
  public void define(Context context) {
    // implementations of extension points
    context.addExtensions(FooLanguage.class, ExampleProperties.class);


<?xml version="1.0" encoding="UTF-8"?>


A plugin extension exists only in its associated technical stacks. A scanner sensor is for example instantiated and executed only in a scanner runtime, but not in the web server nor in Compute Engine. The stack is defined by the annotations @ScannerSide@ServerSide (for a web server), and @ComputeEngineSide.

An extension can call core components or another extension of the same stack. These dependencies are defined by constructor injection:

public class Foo {
  public void call() {}
// Sensor is a scanner extension point 
public class MySensor implements Sensor {
  private final Foo foo;
  private final Languages languages;
  // Languages is core component which lists all the supported programming languages.
  public MySensor(Foo foo, Languages languages) { = foo;
    this.languages = languages;
  public void execute(SensorContext context) {
public class ExamplePlugin implements Plugin {
  public void define(Context context) {
    // Languages is a core component. It must not be declared by plugins.
    context.addExtensions(Foo.class, MySensor.class);

It is recommended not to call other components in constructors. Indeed, they may not be initialized at that time. Constructors should only be used for dependency injection.

A compilation will not fail if incorrect dependencies are defined, such as a scanner extension trying to call a web server extension. Still, it will fail at runtime when a plugin is loaded.

Third-party libraries

Plugins are executed in their own isolated classloaders. That allows the packaging and use of 3rd-party libraries without runtime conflicts with core internal libraries or other plugins. Note that since version 5.2, the SonarQube API does not bring transitive dependencies, except SLF4J. The libraries just have to be declared in the pom.xml with the default scope "compile":


<?xml version="1.0" encoding="UTF-8"?>

Technically, the libraries are packaged in the directory META-INF/lib of the generated jar file. An alternative is to shade libraries, for example with maven-shade-plugin. That minimizes the size of the plugin jar file by copying only the effective used classes.

The command mvn dependency:tree gives the list of all dependencies, including transitive ones.


The core component org.sonar.api.config.Configuration provides access to configuration. It deals with default values and the decryption of values. It is available in all stacks (scanner, web server, Compute Engine). As recommended earlier, it must not be called from constructors.

public class MyRules implements RulesDefinition {
  private final Configuration config;
  public MyRules(Configuration config) {   
    this.config = config; 
  public void define(Context context) {
    int value = config.getInt("").orElse(0);

Scanner sensors can get config directly from SensorContext, without using constructor injection:

public class MySensor extends Sensor {
  public void execute(SensorContext context) {
    int value = context.config().getInt("").orElse(0);

In the scanner stack, properties are checked in the following order, and the first non-blank value is the one that is used:

  1. System property.
  2. Scanner command-line ( for instance).
  3. Scanner tool ( of scanner for Maven for instance).
  4. Project configuration defined in the web UI.
  5. Global configuration defined in the web UI.
  6. Default value.

Plugins can define their own properties so that they can be configured from the web administration console. The extension point org.sonar.api.config.PropertyDefinition must be used:

public class ExamplePlugin implements Plugin {
  public void define(Context context) {
       .name("My Property")
       .description("This is the description displayed in web admin console")

The annotation org.sonar.api.config.PropertyDefinition can be used on an extension to declare a property.

    @Property(key="", name="My Property", defaultValue="42")
public class MySensor implements Sensor {
  // ...
public class ExamplePlugin implements Plugin {
  public void define(Context context) {


The class org.sonar.api.utils.log.Logger is used to log messages to scanner output, web server logs/sonar.log, or Compute Engine logs (available from the administration web console). It's convenient for unit testing (see class LogTester).

import org.sonar.api.utils.log.*;
public class MyClass {
  private static final Logger LOGGER = Loggers.get(MyClass.class);
  public void doSomething() {"foo");

Internally, SLF4J is used as a facade of various logging frameworks (log4j, commons-log, logback, java.util.logging). That allows all these frameworks to work at runtime, such as when they are required for a 3rd party library. SLF4J loggers can also be used instead of org.sonar.api.utils.log.Logger. Read the SLF4J manual for more details.

As an exception, plugins must not package logging libraries. Dependencies like SLF4J or log4j must be declared with the scope "provided".

Exposing APIs to other plugins

The common use case is to write a language plugin that will allow some other plugins to contribute additional rules (see for example how it is done for Java analysis). The main plugin will expose some APIs that will be implemented/used by the "rule" plugins.

Plugins are loaded in isolated classloaders. It means a plugin can't access another plugin's classes. There is an exception for package names following pattern org.sonar.plugins.<pluginKey>.api. For example, all classes in a plugin with the key myplugin that are located in org.sonar.plugins.myplugin.api are visible to other plugins.

Serving static resources

If you need to serve static resources from your plugin such as images or JavaScript files, place them in a directory under resources named static (myplugin/src/main/resources/static). At runtime, they'll be available from https://{server}/static/{pluginKey}/{file}.

Configuring plugins for analyzer loading optimization

SonarQube has a feature that allows you to download Sonar analyzers and third-party plugins only when they are really required by the scanner (see Improving performance). To make this feature work, each analyzer or third-party plugin should declare the list of languages on which they expect to raise issues through a new MANIFEST property called Plugin-RequiredForLanguages.

Optimization behavior

At the Scanner level, the behavior is as follows:

  • Case 1: When the property is not set by the plugin, the plugin is downloaded whatever the contents of the project.
  • Case 2: When the property is defined and there are files corresponding to the language declared by the plugin, the plugin is downloaded.
  • Case 3: When the property is defined and there are no files corresponding to the language declared by the plugin, the plugin is not downloaded.

This helps save network bandwidth and speed up the bootstrap of the scans. As a side effect, the logs are also cleaner, with fewer “nothing to do” logs for plugins that really have nothing to perform on the repository content.

Avoiding dependency errors

For plugins that have a dependency on a base analyzer provided by default with SonarQube (for example, a plugin to add rules or reports to an existing language), it is mandatory to add to the MANIFEST the property Plugin-RequiredForLanguages to avoid a hard failure.

Take, for example, plugin sonar-xyz which provides additional rules for Java:

  1. A user scans a repository that only contains Python code.
  2. sonar-xyz is downloaded because it doesn’t declare the new property. So it is downloaded from the server at each scan (case 1 above).
  3. sonar-java is not downloaded because there are no .java files in the repository to scan (case 3 above).
  4. Analysis errors-out because a NoClassDefFoundError is thrown since sonar-xyz has an unsatisfied dependency on sonar-java, which wasn’t downloaded.

Configuration steps

To avoid dependency errors when optimization is enabled, you'll need to:

  1. Upgrade sonar-packaging-maven-plugin to version 1.
  2. Add java to the configuration of sonar-packaging-maven-plugin where “java” is replaced by the language your plugin is dealing with.
  3. Add the property <requiredForLanguages> to the configuration of sonar-packaging-maven-plugin, so that Plugin-RequiredForLanguages is added to the MANIFEST. The property accepts several values such as js,ts,css,web, yaml, etc.

Example configurations are available on the language pages (see Java for example).

API deprecation

Plugin API deprecation policy

The goal of the deprecation policy is to make sure that users are aware of what is changing and have time to adjust before an API component is dropped at a given planned date.

The API deprecation policy states that:

  • An API component must be deprecated before being dropped. Furthermore, if the underlying feature is not being dropped, a replacement component must immediately be provided.
  • A deprecated API component must be fully supported until its drop (For instance the implementation of a deprecated method can't be replaced by throwing a new UnsupportedOperationException()).
  • The API is released independently of SonarQube (see the version compatibility matrix). 
  • All breaking changes in the Plugin API must be preceded by a deprecation period of at least 2 years after the deprecation.

This leads to the following policy recommendations for API users:

  • Regularly monitor the deprecation of API components and check if you’re currently using them. See Monitoring the deprecated API components.
  • If you're currently using deprecated API components:
    • Don't add new uses of it.
    • Make the necessary updates in your next few releases so you’re ready for any breaking changes after the next LTS release.

Deprecation mark

A Plugin API component is marked as deprecated with both:

  • The annotation @Deprecated.
  • The Javadoc tag @deprecated whose message must start with "in x.y", for example: 
* /**
 * @deprecated in 4.2. Replaced by {@link #newMethod()}.
public void foo() {

API Changes

Release 9.3


  • to define whether the files identified with the language should be automatically published to SonarQube.
  • org.sonar.api.batch.sensor.SensorDescriptor#processesFilesIndependently

Release 9.0


  • org.sonar.api.server.rule.RulesDefinitionXmlLoader is deprecated. Use the sonar-check-api to annotate rule classes instead of loading the metadata from XML files.


  • org.sonar.api.ExtensionProvider Use org.sonar.api.Plugin.Context#addExtensions() to add objects to the container.
  • org.sonar.api.batch.sensor.SensorDescriptor#requireProperty(). Use #onlyWhenConfiguration() instead.
  • All API related to preview/issues analysis mode.
  • Coverage types (unit, IT, overall) was removed.
  • Resource perspectives. Use methods in SensorContext.
  • org.sonar.api.platform.Server#getRootDir(). Use ServerFileSystem#getHomeDir().
  • Define quality profiles with BuiltInQualityProfilesDefinition.
  • org.sonar.api.rules.XMLRuleParser. Use the sonar-check-api to annotate rule classes.

Release 8.4


  • org.sonar.api.batch.scm.ScmProvider#forkDate


  • org.sonar.api.rules.Rule#getId() is deprecated and will always throw UnsupportedOperationException.

Release 8.3


  • org.sonar.api.utils.text.JsonWriter

Release 7.8


  • org.sonar.api.web.WebAnalytics


  • org.sonar.api.i18n.I18
  • org.sonar.api.SonarQubeVersion use org.sonar.api.SonarRuntime instead.
  • org.sonar.api.profiles.XMLProfileParser
  • org.sonar.api.notifications.NotificationChannel


  • Pico components relying on reflection to have their start or stop method called. Make your component implements org.sonar.api.Startable instead.

Release 7.7


  • org.sonar.api.batch.scm.ScmProvider#ignoreCommand


  • org.sonar.api.batch.fs.InputFile::status
  • org.sonar.api.resources.Qualifiers#BRC


  • The preview/issues mode of the scanner has been removed.

Release 7.6


  • PostJob moved to project level IoC container.
  • InputFileFilter moved to project level IoC container.


  • New annotation org.sonar.api.scanner.ScannerSide to mark (project level) scanner components.
  • org.sonar.api.batch.fs.InputProject to create issues on projects.
  • org.sonar.api.scanner.ProjectSensor to declare Sensors that only run at the project level.


  • org.sonar.scanner.issue.IssueFilter is deprecated.
  • org.sonar.api.batch.InstantiationStrategy is deprecated.
  • org.sonar.api.batch.ScannerSide is deprecated.
  • org.sonar.api.batch.fs.InputModule is deprecated.
  • The concept of global Sensor is deprecated (use ProjectSensor instead).


  • Support of scanner tasks was removed.
  • RulesProfile is no longer available for scanner side components (use ActiveRules instead).

Release 7.4


  • Allow identity provider to not provide login.


  • Allow sensors to report adhoc rules metadata.


  • org.sonar.api.rules.RuleFinder removed from scanner side.
  • sonar-channel removed from plugin classloader.
  • stop support of plugins compiled with API < 5.2.

Release 7.3


  • RulesDefinitions supports HotSpots and security standards.


  • org.sonar.api.batch.AnalysisMode and org.sonar.api.issue.ProjectIssues since preview mode is already deprecated for a while.

Release 7.2


  • org.sonar.api.batch.sensor.SensorContext#newExternalIssue to report external issues.
  • org.sonar.api.batch.sensor.SensorContext#newSignificantCode to report part of the source file that should be used for issue tracking.
  • org.sonar.api.scan.issue.filter.FilterableIssue#textRange


  • org.sonar.api.scan.issue.filter.FilterableIssue#line

Release 7.1


  • org.sonar.api.Plugin.Context#getBootConfiguration
  • org.sonar.api.server.rule.RulesDefinition.NewRule#addDeprecatedRuleKey to support deprecated rule keys.

Release 7.0


  • org.sonar.api.batch.scm.ScmProvider#relativePathFromScmRootorg.sonar.api.batch.scm.ScmProvider#branchChangedFiles and org.sonar.api.batch.scm.ScmProvider#revisionId to improve branch and PR support.

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARLINT, SONARQUBE, SONARCLOUD, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License