Search code examples
sonarqubesonarqube7

How to set SonarQube Quality Profile rule


In SonarQube, there is one rule for Java Resources should be closed (squid:S2095). This rule has a parameter excludedResourceTypes.

Parameter of the rule squid:S2095

How to set this parameter?


Solution

  • One way you can set it is by going to the Administration -> Analysis Scope of your SonarQube server:

    1. Browse to the your Sonar instance : http://servername:9000
    2. Login as Admin
    3. Click on Administration
    4. Choose the Analysis tab on the left hand side
    5. Go down to the issues block and look at the "Ignore Issues on Multiple Criteria"

    For example, if you want to restrict the following COBOL rule: "Prevent GO TO statement from transferring control outside current module" located in the directories bank/creditcard and bank/bankcard => this one requires two criteria to define it:

     key: cobol:COBOL.GotoTransferControlOutsideCurrentModuleCheck; path:
        bank/creditcard/**/*
    
        key: cobol:COBOL.GotoTransferControlOutsideCurrentModuleCheck; path:
        bank/bankcard/**/*
    

    UPDATE

    You can have SonarQube ignore issues on certain components and against certain coding rules. Go to Administration > General Settings > Analysis Scope > Issues. Note that the properties below can only be set through the web interface because they are multi-valued.

    None of the SonarQube.Issue.* properties can be set by the command line since they are multivalued. Please find the official documentation here.

    These are the SonarQube issue properties:

    • Ignore Issues on Files - Key: sonar.issue.ignore.allfile
    • Ignore Issues in Blocks - Key: sonar.issue.ignore.block
    • Ignore Issues on Multiple Criteria - Key: sonar.issue.ignore.multicriteria
    • Restrict Scope of Coding Rules - Key: sonar.issue.enforce.multicriteria

    If you are looking to apply this rule to a specific SonarQube project, you can do this by going to SonarQube:

    1. Browse to projects
    2. Select your project
    3. Browse to Administration -> General Settings -> Analysis Scope and set the values as shown above.

    SOURCE

    Ignore Issues on Multiple Criteria

    ***UPdate 2: doing a google search looks like there is way to pass this property via POM.xml: https://stackoverflow.com/a/21825470/1766402 but not as per the official documentation.