A server-side plugin annotated with "@ServerSide" is downloaded by sonar scanner

  • versions used : 8.9.1 LTS (scanner : sonar-maven-plugin:3.9.0.2155)
  • error observed :
    We have developed a custom server-side plugin which exposes a endpoint and query sonarqube services (nothing else). It is declared like this :
@ServerSide
public class PrometheusWebService implements WebService {

and it’s added to the plugin class like this :

public class PrometheusExporterPlugin implements Plugin {
  @Override
  /**
   * Define settings and main class for plugin.
   */
  public void define(Context context) {
    (...)
    context.addExtension(PrometheusWebService.class);
  }

When an analysis is launched, this plugin is downloaded on the scanner although it has no “scanner-side” component, and it may crash the analysis since the plugin is compiled with java 11 target and the scanner may be running with java 8.

I can see other metrics plugins around here which target java 11 and don’t have this problem : sonar-generic-metrics/pom.xml at master · ericlemes/sonar-generic-metrics · GitHub

Am I missing something to declare a full server-side plugin ? Or is this a buggy behavior of the scanner or the server ? (we have full control on the scanners so we can upgrade all of them if necessary).

1 Like

The annotation just indicates that the class should be loaded in the server and not in the scanner.
There’s currently no optimization done for the scanner to not download some of the plugins installed in the server.
Starting with SQ 9.0, scanners also need to run with Java 11, so I recommend you upgrade the JRE running the scanner.

Thanks for your answer, unfortunately what you recommend is not realistic : there are still a lot of legacy project which need a JDK 8 to compile, I’ll just have to downgrade the plugin to be java 8 compatible.

Also, maybe you could complete the documentation which says : “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 web server) and @ComputeEngineSide.”