Sonar does not complain about rule when it should

Must-share information (formatted with Markdown):

  • which versions are you using: * Developer Edition * Version 8.2 (build 32929)
  • what are you trying to achieve: Expecting Sonar quality gate to fail due to new code breaking a rule in the quality profile
  • what have you tried so far to achieve this: Sonar quality gate is configured with just one condition on New Code: “Issues greater than 0”. So it should fail if there is new code which breaks one of the rules set in the quality profile. I added one unused import and one duplicated import. The quality gate contains the “Unnecessary imports should be removed” Java rule which should be broken with the new added code, but it is not.

I would need help identifying why the quality gate is not red in this case :confused:

Hello Hugo,

There are several things to confirm in your case:

  • Did you associate the updated Quality Profile with your project? You can check under Project Settings / Quality Profiles. The rule you mention is included in the default Sonar way Quality Profile as well, but it’s worth checking in case you were using something custom previously with this rule missing.
  • In the custom Quality Gate, did you add the condition for “Issues > 0” for New Code or Overall Code?
  • Is the custom Quality Gate associated with the project? This is under Project Settings / Quality Gates.
  • Once you analyzed the code, did any issues appear in the overview screen at all? As the rule regarding unncessary imports is a code smell, I’d expect to see at least 1 (or more) next to Code Smells in the project overview. Check both New and Overall code to be sure.
  • Depending upon when the code change was made and when analysis was performed, your issue could have been reported, but not where expected. E.g. if you changed it prior to first analysis, it’s probably in Overall code but your Quality Gate criteria could be expecting an issue under New code.

Hi Jeff,

Thank you for you reply.

  • Yes, from the beginning the desired quality profile is selected in the project settings. This is not the problem as other issues (for other rules) are reported.
  • The “Issues > 0” condition was added for New Code.
  • Yes, it is from the beginnig.
  • This happened in a branch, so there is no New or Overall code there. If I select the branch I am working where I just added 1 commit to add 1 unused imports, the number of issues in the branch is 0 when it should be 1.
  • Like I mentione in the point above, my test branch now only has 1 commit with one import line added.

Do you have any other suggestion on what to check?

Thanks in advance