Search code examples
sonarqubejacoco-maven-plugin

sonarQube fails to generate coverage file


Im having trouble getting sonarQube to output the coverage report of my java Spring project. Because of this it always displays 0.0% coverage in the interface. I followed this and it still will not generate the file. The following is the relevant part of the pom.xml and at the bottom is the log. By default the coverage report is supposed to be in target/site/jacoco/jacoco.xml; however even when I comment out <sonar.converage.jacoco.xmlReportPath/> it still does not output anything.

    <sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml
        </sonar.coverage.jacoco.xmlReportPaths>
        <sonar.exclusions>
            **/atlas/base/api/config/*.java,
            **/atlas/base/api/model/*.java,
            **/atlas/base/api/repository/*.java
            **/atlas/bse/api/ClientIntegrationApplication.java
        </sonar.exclusions>
        <!-- JaCoCo Properties -->
        <jacoco.version>0.8.7</jacoco.version>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<!--        <sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath>-->
        <sonar.language>java</sonar.language>
.
.
.
        <dependency>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.6</version>
        </dependency>
.
.
.
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <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>
[INFO] --- sonar-maven-plugin:3.9.0.2155:sonar (default-cli) @ **** ---
[INFO] User cache: C:\Users\***\.sonar\cache
[INFO] SonarQube version: 9.1.0
[INFO] Default locale: "en_US", source code encoding: "UTF-8"
[INFO] Load global settings
[INFO] Load global settings (done) | time=168ms
[INFO] Server id: BF41A1F2-**
[INFO] User cache: C:\Users\***\.sonar\cache
[INFO] Load/download plugins
[INFO] Load plugins index
[INFO] Load plugins index (done) | time=115ms
[INFO] Load/download plugins (done) | time=263ms
[INFO] Process project properties
[INFO] Process project properties (done) | time=48ms
[INFO] Execute project builders
[INFO] Execute project builders (done) | time=43ms
[INFO] Project key: as:asdf
[INFO] Base dir: C:\Code\***\***
[INFO] Working dir: C:\Code\***\***\target\sonar
[INFO] Load project settings for component key: '***'
[INFO] Load project settings for component key: '***' (done) | time=37ms
[INFO] Load quality profiles
[INFO] Load quality profiles (done) | time=87ms
[INFO] Load active rules
[INFO] Load active rules (done) | time=2291ms
[INFO] Indexing files...
[INFO] Project configuration:
[INFO]   Excluded sources: **/atlas/base/api/config/*.java, **/atlas/base/api/model/*.java, **/atlas/base/api/repository/*.java
**/atlas/bse/api/ClientIntegrationApplication.java
[INFO] 17 files indexed
[INFO] 2 files ignored because of inclusion/exclusion patterns
[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 tango-maguire-client-integration
[INFO] Load metrics repository
[INFO] Load metrics repository (done) | time=42ms
[INFO] Sensor JavaSensor [java]
[INFO] Configured Java source version (sonar.java.source): 8
[INFO] JavaClasspath initialization
[INFO] JavaClasspath initialization (done) | time=54ms
[INFO] JavaTestClasspath initialization
[INFO] JavaTestClasspath initialization (done) | time=31ms
[INFO] Java "Main" source files AST scan
[INFO] 15 source files to be analyzed
[INFO] Load project repositories
[INFO] Load project repositories (done) | time=44ms
[INFO] 15/15 source files have been analyzed
[INFO] Java "Main" source files AST scan (done) | time=5933ms
[INFO] Java "Test" source files AST scan
[INFO] 1 source file to be analyzed
[INFO] 1/1 source file has been analyzed
[INFO] Java "Test" source files AST scan (done) | time=420ms
[INFO] No "Generated" source files to scan.
[INFO] Sensor JavaSensor [java] (done) | time=6972ms
[INFO] Sensor CSS Rules [cssfamily]
[INFO] No CSS, PHP, HTML or VueJS files are found in the project. CSS analysis is skipped.
[INFO] Sensor CSS Rules [cssfamily] (done) | time=16ms
[INFO] Sensor JaCoCo XML Report Importer [jacoco]
[WARNING] No coverage report can be found with sonar.coverage.jacoco.xmlReportPaths='C:\Code\TheAtlasTango\tango-maguire-client-integration\target/site/jacoco-aggregate/jacoco.xml'. Using default locations: target/site/jacoco/jacoco
.xml,target/site/jacoco-it/jacoco.xml,build/reports/jacoco/test/jacocoTestReport.xml
[INFO] No report imported, no coverage information will be imported by JaCoCo XML Report Importer
[INFO] Sensor JaCoCo XML Report Importer [jacoco] (done) | time=47ms
[INFO] Sensor C# Project Type Information [csharp]
[INFO] Sensor C# Project Type Information [csharp] (done) | time=22ms
[INFO] Sensor C# Analysis Log [csharp]
[INFO] Sensor C# Analysis Log [csharp] (done) | time=32ms
[INFO] Sensor C# Properties [csharp]
[INFO] Sensor C# Properties [csharp] (done) | time=0ms
[INFO] Sensor SurefireSensor [java]
[INFO] parsing [C:\***\target\surefire-reports]
[INFO] Sensor SurefireSensor [java] (done) | time=158ms
[INFO] Sensor JavaXmlSensor [java]
[INFO] 1 source file to be analyzed
[INFO] 1/1 source file has been analyzed
[INFO] Sensor JavaXmlSensor [java] (done) | time=279ms
[INFO] Sensor HTML [web]
[INFO] Sensor HTML [web] (done) | time=21ms
[INFO] Sensor XML Sensor [xml]
[INFO] 1 source file to be analyzed
[INFO] 1/1 source file has been analyzed
[INFO] Sensor XML Sensor [xml] (done) | time=360ms
[INFO] Sensor VB.NET Project Type Information [vbnet]
[INFO] Sensor VB.NET Project Type Information [vbnet] (done) | time=16ms
[INFO] Sensor VB.NET Analysis Log [vbnet]
[INFO] Sensor VB.NET Analysis Log [vbnet] (done) | time=25ms
[INFO] Sensor VB.NET Properties [vbnet]
[INFO] Sensor VB.NET Properties [vbnet] (done) | time=0ms
[INFO] ------------- Run sensors on project
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=65ms
[INFO] Sensor Java CPD Block Indexer
[INFO] Sensor Java CPD Block Indexer (done) | time=71ms
[INFO] SCM Publisher SCM provider for this project is: git
[INFO] SCM Publisher 1 source file to be analyzed
[INFO] SCM Publisher 0/1 source files have been analyzed (done) | time=223ms
[WARNING] Missing blame information for the following files:
[WARNING]   * pom.xml
[WARNING] This may lead to missing/broken features in SonarQube
[INFO] CPD Executor 4 files had no CPD blocks
[INFO] CPD Executor Calculating CPD for 11 files
[INFO] CPD Executor CPD calculation finished (done) | time=55ms
[INFO] Analysis report generated in 183ms, dir size=184.4 kB
[INFO] Analysis report compressed in 488ms, zip size=60.6 kB
[INFO] Analysis report uploaded in 53ms
[INFO] ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=atlas%3Atango-maguire-client-integration
[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://localhost:9000/api/ce/task?id=AXx7eZTCNRdggghymtti
[INFO] Analysis total time: 15.831 s
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  22.053 s
[INFO] Finished at: 2021-10-13T14:05:38-07:00
[INFO] ------------------------------------------------------------------------


Solution

  • It seems that you're executing "mvn sonar:sonar" - the "sonar" goal will NOT generate the coverage report, it expects that the coverage report has already been generated. The "prepare-agent" goal is responsible for generating an .exec file and the "report" goal generates a .xml report from the .exec file. In your configuration the "report" goal is bound to the package phase, did you run "mvn package" or "mvn install" before running "mvn sonar:sonar"?