We have an Android/Blackberry project with a common part. That part, obviously, is written to compile to both Android and Blackberry targets, and, consequently, cannot use some of the newer Java features (e.g., Integer.valueOf). I'd like to skip some of the rules specifically for that part. Is there a way to do this?
2 Answers
If you separate the common part to an own project you can add a new Quality Profile in Sonar (where you deactivated these rules) and assign it to your common project.
Apart from that you can use the
// NOSONAR
comment to supress a warning on a single line (see FAQ).

- 47,963
- 16
- 124
- 157
-
3Sonar 2.5 introduced a "SuppressWarning" annotation which also useful for switching off analysis http://jira.codehaus.org/browse/SONAR-1760 – Mark O'Connor Jul 16 '11 at 12:06
-
Unfortunately, annotations are among those newer features that are not supported on Blackberry. – Fixpoint Jul 21 '11 at 08:48
-
As to the NOSONAR comment, there are too many violations to comment them all. – Fixpoint Jul 21 '11 at 08:48
-
1So follow the original advice and create a new more permissive quality profile in Sonar. You can make this the default for all projects. – Mark O'Connor Jul 25 '11 at 11:56
-
This is an older question and I think meanwhile there is a better solution:
Adding // NOSONAR to the relevant classes solves the issue somehow. But I think this is problematic since no rules will be applied in this case at all. There is another way to solve this though: Ignore Issues on Multiple Criteria
Example:
I want to ignore all issues against coding rule MagicNumbers in the package com.foobar.domain in all my java files.
In Sonar navigate to your project, go to Configuration\Settings\Issues and in Ignore Issues on Multiple Criteria add:
- Rule Key Pattern: com.puppycrawl.tools.checkstyle.checks.coding.MagicNumberCheck
- File Path Pattern: com/foobar/domain/*.java
This is all also explained very nicely in the linked documentation.

- 21,314
- 2
- 24
- 20
-
1Is there a way to achieve this by adding something similar in the SonarSettings.xml from the project? – Buda Gavril Nov 29 '16 at 09:45