Hi community, I’m using SonarQube 8.9 now and this property is not supported anymore sonar.jacoco.reportPath so I was looking for some guides how to use JaCoCo with sonar in 8.9 version and found next topic:
[Coverage & Test Data] Importing JaCoCo coverage report in XML format
In this topic said: " By default the generated report will be saved under target/site/jacoco/jacoco.xml
; this location will be checked automatically by the sonar-jacoco plugin so no further configuration is required." And there are examples of setuping sonar-jacoco plugin for maven and gradle. I’ve downloaded sonar-jacoco-plugin-2.3.jar from the repository link which attached to the above topic, but where should I place this jar? I’ve also tried this scenario : https://github.com/SonarSource/sonar-scanning-examples/tree/master/sonarqube-scanner-ant/ant-coverage (added all needed jars, add all information from build.xml file which was related to jacoco report to my xml file) but it didn’t work for me, build was failed with next exception:
BUILD FAILED
[2022-04-07T14:02:04.698Z] /home/jenkins/hybris/bin/platform/build.xml:72: The following error occurred while executing this line:
[2022-04-07T14:02:04.698Z] /home/jenkins/hybris/bin/platform/resources/ant/sonar.xml:104: Unable to read execution data file /home/jenkins/hybris/bin/platform/target/jacoco.exec
Caused by: java.nio.file.NoSuchFileException: /home/jenkins/hybris/bin/platform/target/jacoco.exec
My configuration in xml:
<property name="src.dir" location="./src/main/java" />
<property name="result.dir" location="./target" />
<property name="result.classes.dir" location="${result.dir}/classes" />
<property name="result.report.dir" location="${result.dir}/site/jacoco" />
<property name="result.exec.file" location="${result.dir}/jacoco.exec" />
<property name="sonar.coverage.jacoco.xmlReportPaths" value="${result.report.dir}/report.xml" />
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<!-- Update the following line with the location to the jacocoant.jar -->
<classpath path="path/to/jacoco-0.8.7/lib/jacocoant.jar" />
</taskdef>
<taskdef uri="antlib:org.sonar.ant" resource="org/sonar/ant/antlib.xml">
<!-- Update the following line, or put the "sonar-ant-task-*.jar" file in your "$HOME/.ant/lib" folder -->
<classpath path="path/to/sonar/ant/task/lib/sonarqube-ant-task-*.jar" />
</taskdef>
<target name="sonar">
<jacoco:report>
<!-- This task needs the collected execution data and ... -->
<executiondata>
<file file="${result.exec.file}" />
</executiondata>
<!-- the class files and optional source files ... -->
<structure name="JaCoCo Ant Example">
<classfiles>
<fileset dir="${result.classes.dir}" />
</classfiles>
<sourcefiles encoding="UTF-8">
<fileset dir="${src.dir}" />
</sourcefiles>
</structure>
<!-- to produce reports in different formats. -->
<html destdir="${result.report.dir}" />
<csv destfile="${result.report.dir}/report.csv" />
<xml destfile="${result.report.dir}/report.xml" />
</jacoco:report>
<sonar:sonar />
</target>
Does anybody have any links/guides how do the same for ant (configure sonar-jacoco plugin for ant) so on Jenkins build when sonar performs JaCoCo xml report will be generated and in SonarQube project we will have lines coverage in % ?