Sonarqube is not able to load jacoco coverage report

Sonarqube is not able to pick the report generated by jacoco.

profile using;

<profiles>
		<profile>
			<id>coverage</id>
			<activation>
				<activeByDefault>true</activeByDefault>
			</activation>
			<build>
				<plugins>
					<plugin>
						<groupId>org.springframework.boot</groupId>
						<artifactId>spring-boot-maven-plugin</artifactId>
						<version>${project.parent.version}</version>
					</plugin>
					<plugin>
						<groupId>org.sonarsource.scanner.maven</groupId>
						<artifactId>sonar-maven-plugin</artifactId>
						<version>3.9.1.2184</version>
					</plugin>
					<plugin>
						<groupId>org.jacoco</groupId>
						<artifactId>jacoco-maven-plugin</artifactId>
						<version>0.8.6</version>
						<configuration>
							<destFile>${project.basedir}/target/coverage-reports/jacoco-unit.exec</destFile>
							<dataFile>${project.basedir}/target/coverage-reports/jacoco-unit.exec</dataFile>
							<output>file</output>
							<append>true</append>
							<excludes>
								<exclude>*MethodAccess</exclude>
							</excludes>
						</configuration>
						<executions>
							<execution>
								<id>jacoco-initialize</id>
								<goals>
									<goal>prepare-agent</goal>
								</goals>
								<phase>test-compile</phase>
							</execution>
							<execution>
								<id>jacoco-site</id>
								<phase>verify</phase>
								<goals>
									<goal>report</goal>
								</goals>
							</execution>
						</executions>
					</plugin>
				</plugins>
			</build>
		</profile>
	</profiles>

properties:

<properties>
		<java.version>11</java.version>
		<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
		<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
		<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/jacoco.exec</sonar.coverage.jacoco.xmlReportPaths>
		<jacoco.version>0.8.6</jacoco.version>
		<sonar.language>java</sonar.language>
	</properties>

error:

[INFO] Sensor JaCoCo XML Report Importer [jacoco]
 [WARNING] No coverage report can be found 
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=30ms

Hi,

Welcome to the community!

Did you generate the report before analysis?

 
Ann

Hi Ann,
Thanks for your response.
I am not really sure about it. I defined all dependencies in pom.xml.
How can I check?

Naren

Hi Naren,

It’s not a question of just defining the dependencies. You need to research how to use the coverage tool you’ve chosen.

 
HTH,
Ann

Hi,
After test cases are executed, I am generating the report after that importing report to sonarqube.

Hi,

Backing up to your OP:

Analysis isn’t finding your coverage report. The options are:

  • you didn’t tell it where to look
  • you told it where to look, but the file doesn’t exist
  • the file exists, but not where analysis is looking for it

Reviewing your properties, you are providing <sonar.coverage.jacoco.xmlReportPaths>, so the path you’re providing is suspect.

Beyond that, I’ve just scrolled right in your properties block and noticed this:

The .exec format hasn’t been supported for quite a while. An XML report is expected.

Going a little further, it looks like you’re trying to specify what’s actually the default path.

My suggestion: take a look at how to generate an XML JaCoCo report, and try commenting out the JaCoCo report property so analysis can just naturally find it at the default location.

 
HTH,
Ann