0

Based on the question Sonar + Clover only runs on src-instrumented, it is suggested using first mvn clean clover2:setup install clover2:clover, then: mvn sonar:sonar.

Just wonder why we cannot use mvn clean clover2:setup install clover2:clover sonar:sonar?

Community
  • 1
  • 1
Ken
  • 3
  • 2

2 Answers2

1

In the past it was the recommended way to run goal sonar:sonar alone. This is no more the case since SonarQube Scanner for Maven stopped trying to run unit tests + collect coverage for you by forking a new Maven lifecycle.

General advice is now to run goals in a single command. For example mvn clean package sonar:sonar

In the case of Clover the clover:setup goal will alter the Maven Model to make all other plugins (like surefire) use instrumented classes instead of original source code. This is indeed a problem because it will prevent SonarQube to match class files. So in your case you should either stick with two separate goals, or manually configure sonar.sources to refer to original source code.

  • Thanks for your answer. But my problem is if I run all the goals in one single command, the Unit Tests Coverage is blank in the dashboard. I have to run them separately to make sure Unit Tests Coverage is displayed. Is this related with SonarQube version or sonar maven plugin version? From the sonar document it says if using SonarQube instance prior to 4.5, you should use maven-sonar-plugin 2.6, and our company is using SonarQube Version 4.3.2. – Ken Mar 31 '16 at 23:21
  • Thanks, this explanation really makes sense! – Ken Apr 05 '16 at 10:47
0

Compared the maven logs and found the possible reason:

The "mvn clean clover2:setup install clover2:clover sonar:sonar" seems having issue to find the Source dirs. The log shows it uses ${project}\target\clover\src-instrumented and ${project}\target\generated-sources\annotations as the source dirs.

If explicitly specify src/main/java, then this single command works well. The only tricky thing is why running the goals separately doesn't need to specify sonar.sources but the plugin can still find the right folder for source dirs.

Ken
  • 3
  • 2
  • sonar:sonar will get default value of `sonar.sources` from the Maven Model (Maven plugin API). Clover is altering the model (probably to make other plugins like surefire use the instrumented classes). So I will update my answer. – Julien H. - SonarSource Team Apr 04 '16 at 07:37