Several quality profiles for one project

11,229

Solution 1

You can't have multiple profiles for the same project. But if you want this, you just have to create your own custom profile which has all the rules defined in your profiles. For Example, let's say you have quality profile "Android Lint" and "Sonar Way", and if you wan't to check your project against both these profiles, just do the following:

  1. Go to Quality Profiles tab in SonarQube
  2. Click on Back Up on the Profiles you want. It will download an .xml file for each profile.
  3. Just go through the .xml file and figure out how it is written and then Create a new .xml file which contains the rules of both the profiles and give it a cool name.
  4. Go back to Quality Profiles tab in SonarQube
  5. Click on Restore Profile and upload your .xml file.
  6. That's it.

You now have your own custom quality profile with all the rules that you want.

UPDATE: In the latest version of SonarQube (I am using 6.2), you can use the concept of "Inheritance" to combine multiple quality profiles. You can now set a parent quality profile for any profile. Using this you can chain multiple quality profiles.

Solution 2

Applying multiple profiles for one project is not possible.

I see two alternatives: Merging your profiles as already mentioned or scanning the same project under a different "branch" (as in SonarQube terminology).

For a scan under a different branch refer to the sonar quality profile to project association. Please be aware that the syntax of the maven call is actually wrong, use this one instead:

mvn ... -Dsonar.profile="Your profile name" -Dsonar.branch=YOUR BRANCH

Using this will create a new project under the same name plus the branch as postfix. (projectName:branchName)

Regarding the merge of two profiles the easiest way is within the Rules tab:

  1. Select Quality Profile x in Filter View
  2. Bulk Change (in the upper right of the List View)
  3. Activate In
  4. Select Quality Profile y

This will automatically merge the two sets and prevent redundancy.

Solution 3

Just expanding on @guitarium 's answer above:

For SonarQube 7, you can simply do the following on the SonarQube web portal to add extra rules from other profiles into a custom profile (same as merging, really):

  1. Go into Quality Profiles and click the dropdown next to a profile you want to merge
  2. select Copy
  3. Give the copy a cool name
  4. Click on the new copy to go into it's Quality Profiles page
  5. Go to Actions -> Activate more rules
  6. Click Bulk Change , then Activate in and select your new cool profile
  7. You now have a super cool merged profile. Nice job
Share:
11,229

Related videos on Youtube

Wilda
Author by

Wilda

JEE Architect at the SIHM (Harmonie Mutuelle)

Updated on January 09, 2023

Comments

  • Wilda
    Wilda over 1 year

    Is there a way to have several profiles for one project in Sonar ?

    For example we have a Java EE project with : EJB and WebApp (JSP and Back Bean). We have 3 quality profiles: Java, Web and XML. To "execute" these 3 profiles on our project we run three sonar analysis and create 3 result projects in Sonar.

    We use views to regroupe these three projects, is there a way to have one project that use 3 profiles and not use views?

    We want to use views to group different projects and not on the same project.

  • Abubakar
    Abubakar over 7 years
    doesn't this seems very inefficient way for adding new rules?
  • Henry
    Henry over 7 years
    @Abubakar Yes this seems inefficient, but right now this is the only option. There is no way to add multiple profiles in the Sonar Dashboard.
  • JJD
    JJD almost 7 years
    @Henry Is this still valid for recent version of SonarQube?
  • Henry
    Henry almost 7 years
    @JJD The answer is valid but now I use "Inheritance" to get the job done. I have updated my answer. Thanks for pointing this out.