Thursday 23 November 2017

How to configure Jacoco plugin in Maven

Guys, for getting the unit test coverage report in SonarQube for code quality and analysis, let us look into how to use the Jacoco plugin for the same. In this post we'll see how to configure Maven with the Jacoco plugin. FYI Jacoco is a free code coverage tool for Java


In your main parent POM, let us enter the Sonar properties firstly, as follows :

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Sonar -->
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
<sonar.language>java</sonar.language>
<drools.version>5.5.0.Final</drools.version> 
</properties> 

Now in the <pluginManagement> section, let us enter the configuration for the Jacoco plugin.

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.2.201409121644</version>
<configuration>
<destFile>${sonar.jacoco.reportPath}</destFile>
<append>true</append>
</configuration>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

Hope it helps guys. Until next time, ciao!

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
eXTReMe Tracker