Add new custom rules for Java in Sonarqube

The documentation includes general guidance on adding coding rules, including which languages support adding custom rules, and general guidance on how to go about it.
If the docs don’t answer your question, please tell us:

  • What language are you writing rules for? Java
  • What have you tried, and what’s your challenge / stumbling block : Unable to add new rule using REST API call /Postman and getting 401
    post call: http://localhost:9099/api/rules/create
    with authentication ,

Please share the relevant code snippet, along with any error messages you’re encountering:sample request for rule:{
“key” : “squid:S2068”,
“name” : “sample_rule”,
“description” :“Credentials should not be hard-coded”,
“language”:“java”,
“type”:“Vulnerability”,
“severity”:“Blocker”,
“tags”:“cert,cwe,owasp-a2,sans-top25-porous”

}
}

Hi,

That’s not what that API is for. The onboard documentation of that API isn’t fulsome, by any means, but this subtle point is the important one:

That call is used to create rules from existing template rules that already exist in your SonarQube instance.

For brand new rules, not created from a template, you’ll need to write a plugin in Java.

 
HTH,
Ann

Hi @ganncamp
Thanks for the confirmation,
As i understand from your comment that , we cannot use REST API for adding new rules on existing java rules/existing template, by using java plugin only we can add new rules which are not exist in Sonarqube.

We are in process to add new AEM specific rules on Sonarqube as part of AEM as cloud migration.
We will check other plugin options to add AEM specific rules and keep you posted if anything required.
Thanks again.

Cheers
Raju Komari

Hi Raju,

You CAN use the API for creating new rules from an existing template.

Yes, correct.

You may be interested in the AEM plugin that’s available in the Marketplace. If it doesn’t provide the rules you need, it may serve as a template for writing your own plugin.

 
HTH,
Ann