Custom Plugin (Java) created but unable to see results in SonarQube

Developed a custom SonarQube plugin (using Java) per version 7.9.5.

The plugin has been developed by myself and a small team; however the documentation is awful and we’re incredibly lost as to how to see results in SonarQube. The only thing that we have at this point is context.reportIssue() when we want to raise an issue. We believe there is much more being missed but can’t find anything to get us the info we need to know what comes next. Honestly, we need to raise an issue (only at the class level) and I’m not even sure we’re doing that right (and ultimately aggregate the results into a project level measure too). Unable to find resources online to on that either to help realize that one way or the other.

1.) Created a new metric and am unable to find anything useful online as to how to report the measure to SonarQube under the metric.

2.) Ideally, We’d be able to see a project level measure (percentage) and within it, a class level measure (percentage) right in SonarQube. Note that the plugin is loaded into the extensions/plugins folder. Able to see the plugin in SonarQube but nothing from our new rule.

Can anyone help please?

Please note that between myself and the others working with me… we have seen just about every potentially useful piece of documentation that is easy and not easy to find on the internet. Need something that can spell it out like any normal good documentation would.


  • What should we be studying to accomplish this? e.g.(referral to someone or some specific thorough documentation… Not Sonars Docs as they aren’t so great on this topic or any topic related to the bowels of custom plugin development for this platform).

  • What would be required from a development standpoint? e.g.(separate Sonar project, some form of widget creation in the custom plugin project itself, etc…)

  • Anything else you can refer me to or enlighten me on?

To be honest, if anyone would be up for a short one-on-one, would really appreciate it.

This is first time doing ‘anything’ Sonar** and anything you have helps.


What are all the _java.html and _java.json files in the src/main/resources? Can’t find anything online on these that really explain where / how they are used or can be used.

Thank you ‘so’ much in advance for you guidance here.

Hey @jmcnally2020, and welcome to this community!

Sorry for the late replay, posting just before Christmas was maybe not the best time to ask such a big question and get a lot of answers.

It’s not that clear to me what you - and your team - are trying to achieve:

  • Are you trying to write you own SonarQube plugin to do something completely new? (we speak about a “custom plugin”)
  • Are you just trying to add some new rules to the java analyzer, relying on its API (we speak here of a “custom rules plugin”)
  • Are you trying to do both? (providing new metrics, doing some new stuff on top of playing new rules, which would require the Java Analyzer to kick in at some point)

The fact that you want to report some issues (on java code?) make me feels that you are actually writing java rules, but you could also try to raise completely new issues out of the blue directly through the SonarQube API.

Just to be sure before we start, did you explore a bit our example custom plugin, in this repository?
(make sure to use the 7.x branch, as you are obviously targeting a 7.9 SQ instance).

You might also want to have a look at the way of writing custom rules here

It should give you examples of things you try to achieve, and maybe allow you to connect some dots.

Now, regarding your other question:

From where do you see them? From the SonarSource Java Analyzer repository?

Because if it’s the case, then these files are just the ones containing the metadata of all the 600+ rules provided by the SonarSource Java analyzer, to be displayed by SQ when browsing rules.

If you need some guidance about how to make some bit of code work, please provide some code snippet of what is actually not working you would like to, so it would help us to answer (and have the correct people jumping in). For instance, as I’m one of the maintainers of the Java Analyzer, I probably won’t be able to help you a lot with completely independent plugins, but I would gladly help designing and writing rules targeting java.

Hope this helps, for a start,

Thank you for your response. I didn’t know you responded until just now. Apologies for delay (and no problem for yours).

To explain better:

We have the “Sonar-Example-Plugin” and are trying to now modify it to our needs.

We have:
1.) One (Check or Rule - unsure because the terms seem to be used interchangably) - that scans test classes one by one to compare assertion count to the method invocation count and returns a class level percentage / ratio.

2.) It extends BaseTreeVisitor and implements JavaFileScanner.

3.) Now we are having one heck of a time trying to figure out how to get the ratio to display in SonarQube per test class and can find no good documentation showing what we need to learn.

4.) So - we decided to take our plugin and keep the ratio code that works and trying to integrate it into the sonar-example-plugin project 7.9.*.

5.) In it, there are sensors, metrics, etc… I’ve created the metric and a sensor, however we ‘really’ need help understanding how to invoke our ratio logic from the sensor which is its own class that implements the BaseTreeVisitor and JavaFileScanner. That way, when it runs, our test classes get analyzed and one ratio per test class gets output to the SonarQube UI. In addition, in that same logic, we are calling reportissue(). Not sure if that is right; but we need to show issues while its running see the metrics per-test-class.

Michael, thank you so much. I really appreciate you offering to help me design and write rules targeting Java. Just very stuck on this learning curve. Could you provide your input on my response above? Depending on what you guys say as to how far off I am conceptually, yes! I may very well need some extra guidance.

Also, I can’t understand - how does a MeasureComputer, Metric, Sensor, Rule, Check fit into evrything?

For example:

  • Does a class that implements MeasureComputer stand on its own and run custom analysis and compute ratios (in my case percentage ratio) to display on Sonar’s UI? Or does it need to be combined with anything like a Sensor?
  • What is the difference between a rule and a check and how do we run them in a class implementing MeasureComputer, or Sensor?

I just can’t find these answers anywhere on the world wide web! Thanks for your patience in advance.

Thanks again Michael. I hope you have a great evening.