How to add new Java Custom rule to default Java Quality Profile?

Hi Team,

We are using Sonarqube * Community Edition* Version 9.6.1.

So we have created one custom rule for Java. Now we are just trying the newly created rule to add to the default java quality profile (sonar-way).

But we are not able to add the rule to the default java quality profile.

So is it possible to add the new rules to the default quality profiles?

Thanks,
Murali Sulam

Hi,

the builtin “Sonar way” quality profiles are read only.
If you want to change/expand it, you need to work with a copy of “Sonar way” quality profile
and add your custom rule there.

Gilbert

1 Like

Hi Gilbert,

Thanks for your quick response.

But still I have some couple of follow-up questions.

1.Is there a way to attach 2 quality profiles to a project in Sonarqube.
2.If the above scenario is not possible, is there a way to create a single quality profile consisting of two already available quality profiles.

Regards,
Murali Sulam

Hi,

  1. no, a sonarqube project has one quality profile per language
  2. no, but you may use this

First create a copy of the Sonar way quality profile, then expand this copy with your custom rules.
Then if you want to add rules from another existing quality profiles use the compare feature.

i.e.
https://yoursonarhost/profiles/show?name=CopyOfSonarWay&language=java
and use compare > select the quality profile you want rules from

qp_compare

the diff dashboard makes it easy to add rules from another quality profile

Gilbert

1 Like

Thanks Gilbert, it really helped us…star_struck

Regards,
Murali Sulam