Hi,
I experiment Sonarcloud for our Open source Leshan project. This is a Java/Maven project.
Here is current topic about that.
Here is the sonarcloud page.
(sorry I repeat this information all time but this is to give some context and also to make each topic self-contained)
We currently use Automatic Analysis but I learned/tried about using the CI-based Analysis with corresponding maven plugin.
Reading Invoking the goal chapter :
When invoking the SonarScanner goal it is recommended that you do it as part of a single maven command in line with the other goals needed for the build. For example:
mvn verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ -Dsonar.organization=<your organization key> \ -Dsonar.projectKey=<your project key>
where the
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
goal follows theverify
goal.This is in contrast to invoking
org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
in a dedicatedmvn
invocation. For example:mvn clean install mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \ -Dsonar.organization=<your organization key> \ -Dsonar.projectKey=<your project key>
The advantage with the first technique is that the SonarScanner has access to the full build context and can therefore make a more thorough analysis. For this reason, the first technique is preferred.
That doesn’t fit at all our current CI configuration at least for PR.
We currently run each maven goal separately.
Why do we do that?
because :
- this allow us to generate custom private comment for each goals.
- this allow us to continue to execute some goals even if
onenot critical one failed.
You could see our main workflow executed on PR here and actions called and comment generated in cases of failure are available here
To better understand; some example :
- if check formatting failed we create a comment but we continue to build.
- if compile failed we do not try to test
- if compile succeed we execute unit-test but if unit-test failed we execute Integration tests anyways.
So “execute sonar goal as part of a single maven command in line with the other goals needed for the build” is very restrictive to us. So concretely what do we lost if we do something like :
mvn clean install
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:sonar \
-Dsonar.organization=<your organization key> \
-Dsonar.projectKey=<your project key>