Reputation: 747
I want to setup my Sonar (Version 6.1) do display my project code coverage. I set up JaCoCo and can generate CodeCoverage locally on my computer using command
mvn clean package
but i fail to upload the coverage to Sonar. To do this i use following command:
mvn -Dsonar.login=< my_login > -Dsonar.password=< my_pwd > -Dsonar.host.url=< sonar URL > -Dsonar.projectKey=< productKey > clean package sonar:sonar -Psonar -Ptomcat
Here is the JaCoco setup in pom.xml
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.plugin.version}</version>
<configuration>
<destFile>${basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
<dataFile>${basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>jacoco-site</id>
<phase>package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
And i see the following output:
[INFO] ------------- Scan risk
[INFO] Language is forced to java
[INFO] Base dir: F:\repo\orchestrator
[INFO] Working dir: F:\repo\orchestrator\target\sonar
[INFO] Source encoding: UTF-8, default locale: ru_RU
[INFO] Quality profile for java: Sonar way
[INFO] Sensor Lines Sensor
[INFO] Sensor Lines Sensor (done) | time=0ms
[INFO] Sensor SCM Sensor
[INFO] Sensor SCM Sensor (done) | time=0ms
[INFO] Sensor Embedded CSS Analyzer Sensor
[INFO] 0 source files to be analyzed
[INFO] Sensor Embedded CSS Analyzer Sensor (done) | time=1ms
[INFO] Sensor Coverage Report Import
[INFO] Sensor Coverage Report Import (done) | time=0ms
[INFO] Sensor Coverage Report Import
[INFO] Sensor Coverage Report Import (done) | time=0ms
[INFO] Sensor Unit Test Results Import
[INFO] Sensor Unit Test Results Import (done) | time=0ms
[INFO] Sensor XmlFileSensor
[INFO] Sensor XmlFileSensor (done) | time=0ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=0ms
[INFO] Sensor Code Colorizer Sensor
[INFO] Sensor Code Colorizer Sensor (done) | time=0ms
[INFO] Sensor CPD Block Indexer
[INFO] JavaCpdBlockIndexer is used for java
[INFO] 0/0 source files have been analyzed
[INFO] Sensor CPD Block Indexer (done) | time=0ms
[INFO] Calculating CPD for 592 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 20712ms, dir size=5 MB
[INFO] Analysis reports compressed in 2506ms, zip size=3 MB
[INFO] Analysis report uploaded in 2704ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://URL/dashboard/index/<ProductId>:parent
[INFO] Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
[INFO] More about the report processing at http://URL/api/ce/task?id=AV68su2eddnYVrlQ9oP-
[INFO] Task total time: 1:36.284 s
It would b great to receive some more information about Code Coverage publishing to Sonar. Any suggestions/hints would b highly appreciated. Thanx!
Upvotes: 4
Views: 5546
Reputation: 16536
Couple of things that could have gone wrong here. First thing that looks fishy is that Sonar reports 0 files to be analysed. It won't upload the coverage for files it didn't analyse.
This might be caused by your wrongly defined profile. The mvn
-P
option accepts a comma-separated list. Chances are your second -Ptomcat
has overridden the first -Psonar
. Better use -Psonar,tomcat
.
Also make sure you run the command in the project root (where the pom.xml
should lie) and that your Sonar server has the Java and Coverage plugins installed and properly configured. The code coverage settings on the server must not exclude java files, for example.
I'd also use validate
instead of package
so your integration tests (failsafe plugin) are run too.
Nitpicking:
-Dsonar.projectKey=< productKey >
is not needed if you're using Maven, except you want to override the default project name from your pom.xml
.
Upvotes: 2