Hi community,
I am having trouble with Sonar reading the coverage information from test result. The version of Sonar I am using is 7.9.2, and the parts of my pom files that refer to sonarqube and jacoco are:
<properties>
<!-- Sonar -->
<skipTests>false</skipTests>
<sonar.projectKey>test-service</sonar.projectKey>
<sonar.projectName>test-service</sonar.projectName>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<project.test.result.directory>${project.build.directory}/test-results</project.test.result.directory>
<sonar.java.codeCoveragePlugin>jacoco</sonar.java.codeCoveragePlugin>
<sonar.coverage.jacoco.xmlReportPaths>${project.test.result.directory}/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
<sonar.language>java</sonar.language>
</properties>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.7.0.1746</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<argLine>${jacocoArgLine}</argLine>
<reportsDirectory>${project.test.result.directory}/surefire</reportsDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<id>pre-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<propertyName>jacocoArgLine</propertyName>
<destFile>${project.test.result.directory}/jacoco/jacoco.exec</destFile>
</configuration>
</execution>
<execution>
<id>post-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.test.result.directory}/jacoco/jacoco.exec</dataFile>
<outputDirectory>${project.test.result.directory}/jacoco</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After I do:
mvn clean package sonar:sonar -‘Dsonar.host.url’=“http://dummy.sonar:8080/”
The jacoco files are generated properly: jacoco.xml and jacoco.exec:
But when I check the result in Sonar, the coverage is 0:
This is the console output:
[INFO] SonarQube version: 7.9.2
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[WARNING] SonarScanner will require Java 11 to run starting in SonarQube 8.x
[INFO] Load global settings
[INFO] Load global settings (done) | time=257ms
[INFO] Server id: ################
[INFO] User cache: ################\.sonar\cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=134ms
[INFO] Load/download plugins (done) | time=168ms
[INFO] Process project properties
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=6ms
[INFO] Project key: test-service
[INFO] Base dir: ############\java\test-service
[INFO] Working dir: ############\java\test-service\target\sonar
[INFO] Load project settings for component key: 'test-service'
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=195ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=1307ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO] 39 files indexed
[INFO] 0 files ignored because of scm ignore settings
[INFO] Quality profile for java: Sonar way
[INFO] Quality profile for xml: Sonar way
[INFO] ------------- Run sensors on module test-service
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=93ms
[INFO] Sensor JavaSquidSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=18ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=10ms
[INFO] Java Main Files AST scan
[INFO] 25 source files to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=79ms
[INFO] 25/25 source files have been analyzed
[INFO] Java Main Files AST scan (done) | time=5195ms
[INFO] Java Test Files AST scan
[INFO] 13 source files to be analyzed
[INFO] Java Test Files AST scan (done) | time=1905ms
[INFO] Java Generated Files AST scan
[INFO] 0 source files to be analyzed
[INFO] Java Generated Files AST scan (done) | time=2ms
[INFO] Sensor JavaSquidSensor [java] (done) | time=7357ms
[INFO] Sensor SurefireSensor [java]
[INFO] 13/13 source files have been analyzed
[INFO] 0/0 source files have been analyzed
[INFO] parsing [################\java\test-service\target\test-results\surefire]
[INFO] Sensor SurefireSensor [java] (done) | time=71ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 1 source files to be analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=136ms
[INFO] 1/1 source files have been analyzed
[INFO] Sensor XML Sensor [xml]
[INFO] 1 source files to be analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=122ms
[INFO] 1/1 source files have been analyzed
[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=41ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=63ms
[INFO] SCM provider for this project is: git
[INFO] 39 files to be analyzed
[INFO] 38/39 files analyzed
[WARNING] Missing blame information for the following files:
[WARNING] * pom.xml
[WARNING] This may lead to missing/broken features in SonarQube
[INFO] 8 files had no CPD blocks
[INFO] Calculating CPD for 17 files
[INFO] CPD calculation finished
[INFO] Analysis report generated in 195ms, dir size=251 KB
[INFO] Analysis report compressed in 216ms, zip size=113 KB
[INFO] Analysis report uploaded in 493ms
[INFO] ANALYSIS SUCCESSFUL, you can browse ##########################
[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 ##########################
[INFO] Analysis total time: 13.672 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:09 min
[INFO] Finished at: 2020-09-28T11:06:21+02:00
[INFO] --------------------------------------------------------
I used ### to hide confidential information.
Thank you upfront and best regards,
Roko