Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven's code coverage for Java 8 project

I want to create a code coverage report for my Java 8 Maven project. I've got a problem with using Cobertura because it fails to handle Java 8 syntax. Anyone familiar with a workaround? Any other Maven plugin?

like image 666
netanel Avatar asked Oct 07 '15 13:10

netanel


1 Answers

Use JaCoCo which works on Java 8.

Here is the plugin XML from my pom:

<build>
...
<plugin>
    <groupId>org.jacoco</groupId>
    <artifactId>jacoco-maven-plugin</artifactId>
    <version>0.7.5.201505241946</version>
    <executions>
        <execution>
            <id>default-prepare-agent</id>
            <goals>
                <goal>prepare-agent</goal>
            </goals>
        </execution>
        <execution>
            <id>default-report</id>
            <phase>prepare-package</phase>
            <goals>
                <goal>report</goal>
            </goals>

        </execution>
        <execution>
            <id>default-check</id>
            <goals>
                <goal>check</goal>
            </goals>
            <configuration>
<rules><!-- implementation is needed only for Maven 2 -->
    <rule implementation="org.jacoco.maven.RuleConfiguration">
        <element>BUNDLE</element>
        <limits><!-- implementation is needed only for Maven 2 -->
            <limit implementation="org.jacoco.report.check.Limit">
                <counter>COMPLEXITY</counter>
                <value>COVEREDRATIO</value>
                <minimum>0.60</minimum>
            </limit>
        </limits>
    </rule>
</rules>
</configuration>
        </execution>
    </executions>
</plugin>
...
</build>

It also has good integration with Continuous Integration Systems like Jenkins

like image 160
dkatzel Avatar answered Nov 05 '22 00:11

dkatzel