Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can maven-sonar-plugin make a local analysis?

I'm configuring a multi-module maven project that force the execution of sonar:sonar in the verify phase.

I also use the build-breaker-plugin of sonar to avoid deploying the module if some alerts are thrown by sonar.

The problem with this approach is that the developer should go to the sonar server to check the alerts. This is not that bad but if several users try to analyses the same module at the same time is impossible to know if the last/current analysis have your alerts.

CONTEXT: we have a CI system that builds all the modules each hour. So sometimes this collides with some developer deploy (that force the analysis)

IMHO, only the CI system should commit the analysis to the sonar server, because the CI have the lasted committed and deployed code. But the developer should only check locally his changes.

So, why we are forcing the analysis in the developer build? To avoid deploying modules that does not respect the code quality thresholds (The build-breaker plugin of sonar helps on this).

There is a way to configure the maven-sonar-plugin to do this?

  • local analysis in the developer build.
  • server analysis in the CI build
like image 750
ggarciao Avatar asked May 30 '12 08:05

ggarciao


People also ask

What does Maven sonar plugin do?

The SonarScanner for Maven is a Maven plugin that allows you to execute SonarCloud code analysis via a regular Maven goal. As a Maven goal, the scanner is available anywhere Maven is available (locally, in CI services, etc.), without the need to manually download, set up, and maintain a separate installation.

What does sonar sonar do?

Sonar uses sound waves to 'see' in the water. NOAA scientists primarily use sonar to develop nautical charts, locate underwater hazards to navigation, search for and map objects on the seafloor such as shipwrecks, and map the seafloor itself. There are two types of sonar—active and passive.

How does SonarQube analysis work?

SonarQube is a Code Quality Assurance tool that collects and analyzes source code, and provides reports for the code quality of your project. It combines static and dynamic analysis tools and enables quality to be measured continually over time.


1 Answers

From what I understand, you should probably have a first instance of Sonar which is only used during the build to break it if your quality requirements are not met, and a second one that is used by your CI system and that is the reference for your products. And if you really want to enforce your process and be sure that code which breaks those requirements is not pushed into your SCM system, then you could bind a Sonar analysis on a pre-commit hook. But this seems a bit extreme to me...

At SonarSource, we haven't chosen the "block a commit because of violations" approach. Indeed, we consider that having some technical debt (= violations) is OK as long as you manage it. Managing technical debt means reviewing each incoming violation in Sonar and fixing them in the code or affecting those violations to action plans, the main idea being that the technical debt should not have increased at the end of a development sprint. This is what the review feature of Sonar is meant for. And Sonar provides widgets to monitor the evolution of reviews and new violations without a review.

like image 81
Fabrice - SonarSource Team Avatar answered Sep 18 '22 23:09

Fabrice - SonarSource Team