I am new to SonarQube, and I was asked in the scope of my studies to put in place measures.
I decided to make my code coverage report with Jacoco and the feed SonarQube with it (for testing reasons, i am making HTTP requests to my own services and need to track the associated code coverage). I’m on this since few days now and can’t figure out what’s the problem.
When I am packaging, testing, and the scanning my project, I successfully build the Jacoco Report wich is located on my file system, and the sonarQube server we use correctly get all others data (Failures, bugs, etc.). But the reports isn’t take in account on SonarQube.
Jacoco Report :
And then, in SonarQube, I get à 0% coverage on all files.
I followed this tread and the sonarQube documentation to build my pom.xml file. Here are the porperties I use. It is voluntary simplified to remove other dependencies’ settings.
<properties> <!-- Maven compiler properties --> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> [...] <!-- SonarQube properties --> <sonar.sources>src/main</sonar.sources> <sonar.tests>src/test</sonar.tests> <sonar.projectKey>an_id</sonar.projectKey> <sonar.host.url>an_url</sonar.host.url> <sonar.login>a_login</sonar.login> <!-- Sonar-JaCoCo properties --> <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> <sonar.language>java</sonar.language> <sonar.coverage.jacoco.xmlReportPaths>target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
Then I configure the maven profile to use Jacoco and make reports on execution as asked.
<profiles> <profile> <id>coverage</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.2</version> <executions> <execution> <id>prepare-agent</id> <goals> <goal>prepare-agent</goal> </goals> </execution> <execution> <id>report</id> <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles>
Seeing the SonarQube documentation and the tread mentionned before, they 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. Just launch
mvn sonar:sonaras usual and the report will be picked up.”
And that’s exactly what i’m doing.
Please note that i have a “Missing blame information for the following files:” warning during the sonar process, but i do not think it is linked.
Also, please note that the command i am using is :
mvn clean package verify sonar:sonar
If needed, here is my complete pom file :
pom.txt (5.2 KB)
It is the only pom i have in my project, and actually my project is mono-module.
Thanks for reading and for your help !