Summary

The JaCoCo Maven plug-in can be used to report on Unit Test coverage in an IDE (e.g. NetBeans) and also for Sonar.

POM file

To analyse your Maven project using JaCoCo, place the following in the build face of the projects top-level POM along with the Jacoco properties for use with Sonar.


<properties>
        <jacoco.version>0.7.4.201502262128</jacoco.version>
        <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
        <sonar.core.codeCoveragePlugin>jacoco</sonar.core.codeCoveragePlugin>
        <sonar.language>java</sonar.language>
</properties>

<build>
        <plugins>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <id>prepare-unit-test-agent</id>
                        <configuration>
                        </configuration>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>jacoco-site</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
</build>
                    

This can now be picked up by running 'code coverage' in the Netbeans IDE or by using Jenkins & Sonar for static build analysis