Updating Custom Java Plugin to SonarQube API 8.6 causes test compile errors

We are currently using

  • SonarQube Server Community Edition Version 8.1.0.31237
  • Sonar Java Code Analyzer 6.3.2.22818

running on a Debian Linux 4.9.0 OS.

We have developed some custom rules based on the Java Code Analyzer.

As we are considering to update the SonarQube Server to Version 8.6, I tried to compile our custom rules plugin with the following Sonar API and Sonar Java rules versions, which are the latest versions according to Maven cetral:

<sonar.plugin.api.version>8.6.0.39681</sonar.plugin.api.version>
<java.plugin.version>6.11.0.24617</java.plugin.version>

Whe I compile the plugin with this configuration the following exception occurs when running the tests:

java.lang.NoSuchMethodError: org.sonar.api.batch.sensor.internal.SensorContextTester.setSettings(Lorg/sonar/api/config/Settings;)Lorg/sonar/api/batch/sensor/internal/SensorContextTester;

at org.sonar.java.testing.InternalCheckVerifier.sonarComponents(InternalCheckVerifier.java:551)
at org.sonar.java.testing.InternalCheckVerifier.verifyAll(InternalCheckVerifier.java:204)
at org.sonar.java.testing.InternalCheckVerifier.verifyIssues(InternalCheckVerifier.java:164)
at de.empic.sonar.EapRuleVerifier.verify(EapRuleVerifier.java:32)
at de.empic.sonar.rule.AvoidSpecificCDIBeanNameTest.detected(AvoidSpecificCDIBeanNameTest.java:10)
...

Whe I use the API version 8.2.0.32929, which is mentioned in the guide Writing Custom Java Rules 101, everything works fine. Any version higher than that, leads to the exception above.

That raises the following questions for me:

Is it possible to deploy an run the custom rules plugin having the code dependency on API version 8.2.0.32929 on a SonarQube Server with version 8.6?

When I scanned the server release upgrade notes, I found the following statement in Release 8.5:

Upgrade simplified: Languages, GIT and SVN support now built-in
Languages provided with your edition and support for GIT and SVN version control are now built-in and don’t require plugins. If you were using these plugins, you need to remove them from SonarQube before upgrading.

  • Does this require changes in how I have to develop, build and deploy our custom java rules?
  • How do I know, which version of the java analyzer is bundled with the SonarQube server version?
1 Like

Hello @tschindler,

Normally all the API changes should be registered at https://docs.sonarqube.org/latest/analysis/languages/java/
You may want to look at this page for help.

Olivier

Hello @OlivierK,

thank you for the hint where to find the API Changes of the sonar java plugin. But unfortunately this doesn’t solve my problem, as I don’t see any API Changes concerning my problem.

After some more research and debugging, I found, that in the POM of the “org.sonarsource.java:java:6.11.0.24617” depends on Sonar Version 7.9 (https://search.maven.org/artifact/org.sonarsource.java/java/6.11.0.24617/pom).

When I compile and run my tests with
<sonar.plugin.api.version>7.9</sonar.plugin.api.version>
everything works fine.

In the guide for writing java custom plugins (Writing Custom Java Rules 101, I found the following paragraph:

In the code snippet below, note the plugin API version (<sonar.version>) provided through the properties. It relates to the minimum version of SonarQube your plugin will support, and is generally aligned to your company’s SonarQube instance. In this template, we rely on the version 8.2.0.32929 (LTS version is 7.9, but compatibility to latest release is guaranteed when packaging the plugin). Note that latest released versions of the Java Analyzer are always compatible with the current LTS version of SonarQube.

I guess, my problem stems from an incompatibility in the plugin API between LTS version 7.9 and the latest version 8.6.
So for now, I will keep the dependency to plugin API Version 8.2.0.32929 which works and I will have to upgrade to the next plugin API Version with the next SonarQube LTS Release.

Hello,

I ran into the exactly same problem.
I’d like to upgrade my SonarQube Community Edition installation to 8.6.1.40680 but I’m a bit confused when I try to update my custom Java plugin settings.

Which java.plugin.version should I use since Java plugin isn’t a plugin anymore or, at list, is ‘built in’ ?

Is sonar-java/CUSTOM_RULES_101.md at master · SonarSource/sonar-java · GitHub uptodate for last versions of SonarQube (meaning 8.5 an higher) ?

Thanks

Hello Julien,

I installed locally SonarQube Server Community Edition 8.6.0.39681 and built my custom Java plugin with the following versions:

<sonar.plugin.api.version>8.2.0.32929</sonar.plugin.api.version>
<java.plugin.version>6.11.0.24617</java.plugin.version>

That worked fine. I guess even if the Java plugin is now ‘built in’, there will be a API version to use for custom plugins and I hope it will be documented somewhere, which version is compatible to which SonarQube version.

I don’t know if or when the guide for writing cusom java rules will be updated for the higher version of SonarQube.

Hi,

just to let everyone know who follows this thread:

I just noticed that the guide for developing custom java rules was updated. If you look at it now, in chapter Custom Rules 101 - looking at the POM there is an incompatibility of the Java plugiin version 6.12.0.24852 and SonarQube Server API 8.7:

:exclamation: SonarQube 8.7 compatibility issue

SonarQube 8.7 embed version 6.12.0.24852 of the Java Analyzer, which unfortunately suffer from > a dependency-related-bug. This bug impacts custom-rules plugins compatibility with latest
SonarQube APIs. It might also prevent you to build or run tests of custom-rules plugins.

The issue has been fixed in ticket SONARJAVA-3690, but the fix has been shipped with version 6.13.0.2513 of the Java Analyzer, itself only available for SonarCloud users.

SonarQube 8.8 will embed a newer version of the Java Analyzer (probably version 6.14 ), and the issue will be solved for custom-rules plugins. However, in the meantime, we recommend you to use version 6.13 instead of 6.12 of the Java Analyzer to build your custom plugin. No new APIs has been introduced between these 2 versions, and deploying a custom-rules plugin relying on 6.13 Java Analyzer API on a SonarQube 8.7 having version 6.12 will work just fine.

Still, there is an error in the hint, the version of the Java plugin must be 6.13.0.25138

I hope this helps anyone running in this problem.

Best Regards
Thomas

3 Likes

Indeed, we identified the issue (mainly thanks to this thread) and we were planning to update the tutorial again as soon as version 8.8 of SonarQube is released (planned for this week). It will embed version 6.14 of the java analyzer, released last Friday.

Thanks for noticing the typo. I’ll fix it right now!

Cheers,
Michael

1 Like