Java RulesDefinition not working

Hi, I try to add custom Rule but it didn’t work
I follow sample

What I do

Create an implementation of RulesDefinition

code I got from RulesDefinition interface comments

Then I add an extension to my plugin

Now I suppose I had new rule with id x12

I try to bundle an issue which I will register via sensor with this new custom rule

But it’s didn’t bundle.
Could you provide some sample code how I could register a new custom rule and then create an issue for that rule?

NewAdHocRule I didn’t consider as it has a limited amount of properties

Thanks in advance


You are mixing multiple concepts. Custom rules are extra rules that you develop, based on SonarSource analyzers. Basically we provide an API to simplify the coding of new rules (providing an AST, so that you d’ont have to handle the parsing/inference yourself). The repo is about that. For custom rules, you should not implement a Sensor, but instead the extension point provided by the custom rule API. In the case of SonarJava, the entry point is CheckRegistrar that returns a list of Checks.

Now if you want to develop your own rules, without relying on SonarJava API, you have two options:

  1. If you know in advance the list of possible rules, and want to configure the rules activation/severity/params from SonarQube UI, you should use “normal” rules. Implement RulesDefinition extension point (similar to your exemple above), and then in your Sensor use the method newIssue to create an issue for a specific rule key. Caution: the rule should be activated in the project quality profile to have it ultimately reported in SonarQube.

  2. If you don’t know the list of rules, or more generically you simply want to quickly import third party report of issues, where the rules configuration is managed outside SonarQube, then you can use newExternalIssue, with or without newAdHocRule to give more details about the rule. Note that to import external issues, you could also not develop any Java plugin, but simply feed the scanner with the issue report converted to a specific XML format.

1 Like

Hi @Julien_HENRY, thanks for providing healthy feedback
I managed how to add rules via

and bound them with custom JavaCheck

I still need each issue to have own rich details (text describing reasons why issue happens and some link to point how it could be solved)
I see that each issue had comments and I want to use them to reach my goal.
Could you provide some hint on how I could add comments to new issues I created

I noted there is PostJobIssue so I assume there is some post-process where all issues are created and I could write some my extension to add comments.
I see its possible to add comment

Hi Julien,

I’m Tamir, the Product Manager that works with Vitalii.
What we’re essentially trying to accomplish is to link between an individual exception error to the OverOps root cause. The problem is that each exception has a unique link to our OverOps Automated Root Cause screen (tale.html), and we’re not sure what’s the best way to develop that - whether it’s with Custom Rules and/or Templates.

Please let me know if that makes sense, and if there’s any more product/technical context you need.


@Julien_HENRY I just want to say thanks, you pointed me in right direction