This version of the SonarQube documentation is no longer maintained. It relates to a version of SonarQube that is not active.

See latest version
Start Free
9.6 | Instance administration | Quality profiles

Quality profiles

Quality profiles are a core component of SonarQube where you define sets of rules that, when violated, raise issues on your codebase (for example, methods should not have a cognitive complexity higher than 15). Each individual language has its own quality profile.

To manage quality profiles, navigate to the Quality profiles page. Here, you'll find the profiles grouped by language.

Ideally, all of your projects will be measured with the same profile, but that isn't always practical. For example, you might run into the following situations:

  • You have different technical requirements from one project to another (for example, different rules might apply to a threaded/non-threaded Java application).
  • You want to ensure stronger requirements for some of your projects (for example, internal frameworks).

You can define as many quality profiles as needed to fit your specific needs.

Default quality profiles

Each language must have a default quality profile (marked with the DEFAULT tag). Projects that are not explicitly assigned to specific quality profiles are analyzed using the default quality profiles. There is also at least one built-in Sonar way quality profile for each language. SonarSource creates these quality profiles with rules that generally apply to most projects.

The Sonar way quality profiles are a good starting point as you begin analyzing code, and they start out as the default quality profiles for each language. However, we recommend that you copy this profile (see Copying a profile below) and begin to fine-tune the rules. Why?

  • Default quality profiles are not editable, so you won't be able to customize the Sonar way to your needs.
  • The Sonar way becomes a baseline against which you can track your own quality profiles.
  • The Sonar way may be updated over time to adjust which rules are included and adjust rule severities.

Quality profile permissions

By default, only users with the global Administer Quality Profiles permission can edit quality profiles. This is set at Administration > Security > Global Permissions.

SonarQube also allows users with the global Administer Quality Profiles permission to give an expert or group of experts permission to manage a specific quality profile. These experts only have permission for that quality profile, not all quality profiles. Grant permissions to specific quality profiles on the quality profile's page (Quality Profiles > profile name) under the Permissions heading by clicking the Grant permissions to more users button.

Copying a quality profile

Copying works well when you need to make a few changes to a built-in profile. When you copy a profile, you start off with all of the activated rules from the profile you copied from. From there, you can activate or deactivate rules to fit your needs. After copying a profile, your new profile won't inherit any changes subsequently made to the original profile.

Follow these steps to copy a profile:

  1. Go to the quality profile page (Quality Profiles > profile name) of the profile you want to copy.
  2. Select Copy from the gear drop-down menu in the upper-right corner of the page.
  3. Give your new quality profile a name and click Copy

Extending a quality profile

Extending a profile works well when many or all of your projects follow a set of common rules, but some of your projects also need to follow additional rules. When you extend a profile, you create a child profile based on a parent profile. This child profile inherits all of the rule settings from the parent profile. If rules are activated or deactivated in the parent profile, they're activated or deactivated in the child profile.

While you can activate rules in your child profile that are deactivated in the parent profile, you cannot deactivate rules in the child profile that are active in the parent profile.

Follow these steps to extend a profile:

  1. Create a base profile with your core set of rules by clicking the Create button on the Quality Profiles page, or use an existing profile as a base profile.
  2. From the Quality Profiles page (Quality Profiles > profile name), find your base profile in the list of Quality Profiles and select Extend from the gear drop-down menu.
  3. After giving your new profile a name, SonarQube opens your new profiles page.
  4. Below the Rules table, click Activate More to add rules to your extended profile.
  5. From the Inheritance table, you can see the hierarchy of inheritance for your profile, and you can change the parent profile by clicking the Change Parent button.

Your new profile has all of the activated rules from the profile you copied, but you can activate or deactivate any rules from the Rules table by clicking the numbers in the Active and Inactive columns.

When you copy a profile, your new profile does not inherit any future rule updates made to the original profile.

Comparing two quality profiles

You can compare the activated rules between two Quality Profiles. This is especially useful when you're using a quality profile copied from another profile as you won't automatically inherit new rules added to the original quality profile. Comparing your custom quality profile to the original quality Pprofile shows any additional activated rules that aren't in your quality profile.

To compare two profiles:

  1. From the Quality Profiles page, click the name of the first profile you'd like to compare.
  2. Select Compare from the drop-down menu.
  3. Select the second profile you'd like to compare from the Compare with drop-down menu.

From here you can activate rules between the two profiles using the arrow buttons.

Knowing what's changed in a quality profile

When SonarQube notices that an analysis was performed with a quality profile that is different in some way from the previous analysis, a quality profile event is added to the project's event log. To see the changes in a profile, navigate to the profile (Quality Profiles > profile name) and choose Changelog. This may help you understand how profile changes impact the issues raised in an analysis.

Additionally, users with quality profile administration privileges are notified by email each time a built-in profile is updated. These updates can be caused by updating SonarQube or updating third-party analyzers.

Using a quality profile on another SonarQube instance

To use a profile from one SonarQube instance on another SonarQube instance, take the following steps:

  1. From the source SonarQube instance, open the quality profile you want to use.
  2. Select Back up from the gear drop-down menu. This exports the profile as an XML file.
  3. From the target SonarQube instance, click the Restore button on the Quality Profiles main page.
  4. Choose the XML file that you exported previously, and click Restore.

Using a non-default quality profile on a project

One profile for each language is marked as the default profile. Barring any other intervention, all projects that use that language will be analyzed with that profile. To have a project analyzed by a non-default profile instead, start from Quality Profiles, and click through on your target profile, then use the Projects part of the interface to manage which projects are explicitly assigned to the profile.

Ensuring your quality profile has all relevant new rules

Each time a new SonarQube version is released, new rules are added. New rules won't appear automatically in your profile, however, unless you're using a built-in profile or a profile extended from a built-in profile (see the Extending a profile section above).

If you're not using a built-in profile, you can compare your profile to the built-in profile to see what new on-by-default rules you're missing (see the Comparing two quality profiles section above).

Another option is to go to the Rules page in SonarQube and use the Available Since search facet to see what rules have been added to the platform since the day you upgraded.

And finally, the Quality Profiles main page shows recently added rules in the Recently Added Rules section on the right side of the page.

Avoiding deprecated rules

The Deprecated Rules section of the Rules page is your first warning that a profile contains deprecated rules. This section with a pink background gives the total number of instances of deprecated rules that are currently active in profiles and a breakdown of deprecated rule count per profile. Clicking through here takes you to the Rules page to edit the profile in question.

Alternatively, you can perform a Rules search for the rules in a profile (either manually or by clicking through from the Quality Profiles page) and use the Status rule search facet to narrow the list to the ones that need attention.

Security

The Quality Profiles page can be accessed by any user (even anonymous users). All users can view every aspect of a quality profile. That means anyone can see which rules are included in a profile, which rules have been left out, how a profile has changed over time, and compare the rules in any two profiles.

To make rule profile changes (create, edit, or delete) users must be granted the Administer Quality Profiles and Gates permission.

project administrator can choose which profiles their project is associated with.


Was this page helpful?

© 2008-2024 SonarSource SA. All rights reserved. SONAR, SONARSOURCE, SONARQUBE, and CLEAN AS YOU CODE are trademarks of SonarSource SA.

Creative Commons License