使用声纳 checkstyle 插件纪念 @SuppressWarnings

Mar*_*cin 4 checkstyle suppress-warnings sonarqube

是否有可能使用 Checkstyle 插件配置 SonarQube 5.1 以遵守@SuppressWarnings("deprecation")注释。我不想关闭“避免使用不推荐使用的方法”规则,我只想让 SonarQube 尊重@SuppressWarnings注释。

我有一个 Java 代码,我需要在其中使用不推荐使用的createValidator()方法,如下所示:

@SuppressWarnings("deprecation")
@Override
public javax.xml.bind.Validator createValidator() throws JAXBException {
    return contextDelegate.createValidator();
}
Run Code Online (Sandbox Code Playgroud)

Java 编译器在编译代码时不会发出警告,但不幸的是,带有 CheckStyle 插件的 SonarQube 出现了一个问题:

squid:CallToDeprecatedMethod
Avoid use of deprecated methods
Run Code Online (Sandbox Code Playgroud)

bar*_*uin 5

鱿鱼是另一种野兽。正如SonarQube docs 中所建议的,您必须使用稍微不同的语法,例如:

@SuppressWarnings("squid:CallToDeprecatedMethod")
Run Code Online (Sandbox Code Playgroud)

该字符串squid:CallToDeprecatedMethod是 SonarQube规则键

不幸的是,这意味着添加两个注释以有效抑制弃用警告。但是 afaik,这是禁用规则的唯一方法。