How to show sonar issues as compile time error?

2.1k views Asked by At

I am working on eclipse and using SonarLint plugin(SonarQube plugin is deprecated for eclipse Neon) for Code Analysis. I able to connect to Sonar qube server and bind the project to it and the sonar issue are shown in the SonarLint Console.

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

The sonar issues should work as compile time error which does not allow the code to be executed unless fixed.

My Eclipse Screenshot with code

enter image description here

If you see above

"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 .

2

There are 2 answers

0
Mohammad Javed On

After lot of research , I found that it is not possible to show code quality failures as error with Sonar Qube.

Quality failures should be removed by code refactoring from peers or fellow architect based on some best of breed practices.

But we can achieve the same using Google's Error Prone which is using Bazel as the build engine.

0
lbndev On

As you found out, reporting errors at compile time is not possible.

Here's what I can think of, to come close to your need :

  • Configure Eclipse editor to show SonarLint items as errors (but this won't prevent the code from executing) : Preferences > SonarLint > Severity of SonarLint markers (=> set it to Error).
  • Install the BuildBreakerPlugin so that the maven build will fail if the quality gate is broken. I have used it before, with sonar.buildbreaker.skip=true by default, except in the CI deployment pipeline, so that no code breaking the quality gate would make it to test/prod.