java - 如何将 Sonar 问题显示为编译时错误?

标签 java eclipse sonarqube sonarqube-scan

我正在使用 eclipse 并使用 SonarLint 插件(SonarQube 插件已在 eclipse Neon 中弃用)进行代码分析。 我能够连接到 Sonar qube 服务器并将项目绑定(bind)到它,并且 Sonar 问题显示在 SonarLint 控制台中。

I want these issues to be shown as compile time error so as to stop the developer from proceeding further without fixing that issue.

Sonar 问题应该作为编译时错误,除非修复,否则不允许执行代码。

带有代码的我的 Eclipse 屏幕截图

enter image description here

如果你看到上面

"Remove this call to "exit" or ensure it is really required" is a error but is shown as just a warning inside the code. Can we display the same thing as compile time error inside the code as it is high priority error to keep a check on the code quality which cannot be skipped .

最佳答案

正如您所发现的,在编译时报告错误是不可能的。

这是我能想到的,以接近您的需求:

  • 配置 Eclipse 编辑器以将 SonarLint 项目显示为错误(但这不会阻止代码执行):首选项 > SonarLint > SonarLint 标记的严重性(=> 将其设置为错误)。
  • 安装BuildBreakerPlugin这样,如果质量门被破坏,Maven 构建将会失败。我之前已经使用过它,默认情况下使用 sonar.buildbreaker.skip=true ,除了在 CI 部署管道中,这样就不会破坏质量门的代码进入测试/生产阶段。

关于java - 如何将 Sonar 问题显示为编译时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41224051/

相关文章:

java - 在 HostnameVerifier 中信任 peerHost 是否安全?

java - 如何在 JavaFx 中显示按钮中的所有文本

java - 如何在 Eclipse 中增加 Permgen 的大小

java - 在 Android 设备上运行 scala 代码

java - 一个java程序中有2个方法

python - Pydev、eclipse 和 pythonpath 问题

email - 如何配置 Sonar 通知电子邮件?

maven - JaCoCo 报道缺失

java - 哪些 Java 数据结构具有确定的迭代顺序?

Javadoc 源代码标记