Can I deactivate a Sonar Qube rule just for test classes?
I want to apply different SonarQube rules for production and test code.
For example: squid : S1192: "String literals should not be duplicated". It is quite reasonable in production but for test code is very annoying and can make it less readable.
I see how to deactive the rule but I can only disable it globally. At the same time I do not want to avoid analysing the whole test set.
You can do this in Administration -> Configuration -> Analysis Scope -> Restrict Scope of Coding Rules. You need to specify the code of the rule (without spaces) and a file path pattern to filter. If you use the maven standard
**/src/main/**will work for you.
For more information see the docs where it states that you can:
...exclude files/directories from Issues detection (specific rules or all of them) but analyze all other aspects" and gives details.