问题
Is there any possibility to configure SonarQube 5.1 with Checkstyle plugin to honor the @SuppressWarnings("deprecation")
annotation. I do not want to turn off 'Avoid use of deprecated methods' rule, I just want to SonarQube honor the @SuppressWarnings
annotation.
I have a Java code in which I need to use deprecated createValidator()
method as following:
@SuppressWarnings("deprecation")
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {
return contextDelegate.createValidator();
}
Java compiler does not warning when compiling code, but unfortunately SonarQube with CheckStyle plugin rise a issue:
squid:CallToDeprecatedMethod
Avoid use of deprecated methods
回答1:
Squid is a different kind of beast. As suggested in the SonarQube docs, you'll have to use a slightly different syntax, e.g.:
@SuppressWarnings("squid:CallToDeprecatedMethod")
The string squid:CallToDeprecatedMethod
is the SonarQube rule key.
Unfortunately, this means adding two annotations to effectively suppress the deprecation warning. But afaik, it's the only way short of disabling the rule.
回答2:
Squid is a name or number of Sonar Rule, no relationship to checkstyle, all checkstyle rules are described at http://checkstyle.sourceforge.net/checks.html
来源:https://stackoverflow.com/questions/33379959/honoring-suppresswarnings-with-the-sonar-checkstyle-plugin