Code Coverage percentage is 0% in SonarQube Dashboard

10,678 views
Skip to first unread message

balaji....@gmail.com

unread,
May 8, 2018, 5:59:30 AM5/8/18
to SonarQube
Hi Team,

We are trying to run theCode Coverage Pipeline job in Jenkins then we are getting the below error and the Coverage is showing 0% in SonaQube Dashboard.

Please find the below details:

SonarQube version: 6.7.1
Jacoco Version: 0.8.0
Java Version: 1.7

Pipeline Script:
*****************
steps {
        container('maven') {
          // Run Maven install
          dir ('Geo') {
            script {  
                withSonarQubeEnv('SonarQube Server') {
                  sh """
                    mvn install \
                     org.jacoco:jacoco-maven-plugin:0.8.0::prepare-agent \
                    -Dsonar.host.url=${env.SONAR_HOST_URL} \
                    -Dsonar.login=${env.SONAR_AUTH_TOKEN} \
                    -Dsonar.projectKey=geo-18.5 \
                    -Dsonar.projectName=docker-geo-18.5 \
                    -Dsonar.projectVersion=1.0 \
                    -Dsonar.sources=src \
                    -Dsonar.language=java \
                    -Dsonar.java.binaries=src \
                    -Dsonar.java.source=1.7 \
                    -Dsonar.jacoco.reportPaths=src \
                    -Dsonar.sourceEncoding=UTF-8 \
                    -Dsonar.exclusions=\"src/test/java/com/papa/mapping/geo/**.java\" \
                    sonar:sonar
                  """
    
                }
            }
          }    
        }
      }
    }

POM.xml:
*********
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.papa.mapping.store</groupId>
	<artifactId>store</artifactId>
	<version>0.0.1</version>
	<packaging>jar</packaging>

	<name>store</name>
	<description>Store Spring Boot Service</description>

	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>1.5.9.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
		<spring-cloud.version>Edgware.RELEASE</spring-cloud.version>
	</properties>

 <!-- Configuring The JaCoCo Maven Plugin -->
                 <plugin>
                        <groupId>org.jacoco</groupId>
                        <artifactId>jacoco-maven-plugin</artifactId>
                        <executions>
                               <!-- Prepares the property pointing to the JaCoCo runtime agent which 
                                      is passed as VM argument when Maven the Surefire plugin is executed. -->
                               <execution>
                                      <id>pre-unit-test</id>
                                      <goals>
                                             <goal>prepare-agent</goal>
                                      </goals>
                                      <configuration>
                                             <!-- Sets the path to the file which contains the execution data. -->
                                             <destFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</destFile>
                                             <!-- Sets the name of the property containing the settings for JaCoCo 
                                                   runtime agent. -->
                                             <propertyName>surefireArgLine</propertyName>
                                      </configuration>
                               </execution>


                               <!-- Ensures that the code coverage report for unit tests is created 
                                      after unit tests have been run. -->
                               <execution>
                                      <id>post-unit-test</id>
                                      <phase>test</phase>
                                      <goals>
                                             <goal>report</goal>
                                      </goals>
                                      <configuration>
                                             <!-- Sets the path to the file which contains the execution data. -->
                                             <dataFile>${project.build.directory}/coverage-reports/jacoco-ut.exec</dataFile>
                                             <!-- Sets the output directory for the code coverage report. -->
                                         <outputDirectory>${project.build.directory}/jacoco-ut</outputDirectory>
                                      </configuration>
                               </execution>
                        </executions>
                 </plugin>
                 <!-- Configuring The Maven Surefire Plugin -->
                 <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <configuration>
                               <!-- Sets the VM argument line used when unit tests are run. -->
                               <argLine>${surefireArgLine}</argLine>
                               <!-- Skips unit tests if the value of skip.unit.tests property is true -->
                               <skipTests>${skip.unit.tests}</skipTests>
                        </configuration>
                 </plugin>
                 <!-- Configuring The Sonar Plugin -->
                 <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>sonar-maven-plugin</artifactId>
                        <version>3.0.2</version>
                 </plugin>
			
			
		</plugins>
	</build>

Error:
*******
[INFO] Sensor SurefireSensor [java] (done) | time=96ms
[INFO] Sensor JaCoCoSensor [java]
[INFO] JaCoCo report not found: 'src'
[INFO] Sensor JaCoCoSensor [java] (done) | time=2ms
[INFO] Sensor SonarJavaXmlFileSensor [java]
[INFO] Sensor SonarJavaXmlFileSensor [java] (done) | time=1ms
[INFO] Sensor Analyzer for "php.ini" files [php]
[INFO] Sensor Analyzer for "php.ini" files [php] (done) | time=4ms
[INFO] Sensor Zero Coverage Sensor
[INFO] Sensor Zero Coverage Sensor (done) | time=39ms



G. Ann Campbell

unread,
May 15, 2018, 2:56:42 PM5/15/18
to SonarQube
Hi,

You've got a lot going on in that Maven command. First, since you're using Maven, you don't need to specify things like where the source files are; the scanner will pick that up automatically. Second, when you run the first part of that command:

                    mvn install \
                     org.jacoco:jacoco-maven-plugin:0.8.0::prepare-agent

where is your test report generated to? I'm guessing it's not "src".


Ann
Reply all
Reply to author
Forward
0 new messages