JaCoCo: exclude generated methods (using it with Lombok)

As has already been answered, adding lombok.config in the root directory of the project solves the problem, but if you're using Maven and want to avoid adding lombok.config to your repository, you can use the Apache Maven AntRun Plugin in order to generate it automatically on build:

<plugins>
   <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-antrun-plugin</artifactId>
      <version>3.0.0</version>
      <executions>
         <execution>
            <id>lombok-config</id>
            <phase>initialize</phase>
            <goals>
               <goal>run</goal>
            </goals>
            <configuration>
               <target>
                  <propertyfile file="lombok.config">
                     <entry key="config.stopBubbling" value="true" />
                     <entry key="lombok.addLombokGeneratedAnnotation" value="true" />
                  </propertyfile>
               </target>
            </configuration>
            <?m2e execute?> <!-- Optional: enable this execution in Eclipse -->
         </execution>
      </executions>
   </plugin>
</plugins>

Don't forget to instruct your SCM to ignore this autogenerated file.


Use the excludes tag provide by jacoco.

            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.7.4.201502262128</version>
            <configuration>
                <excludes>
                    <exclude>**/config/**</exclude>
                    <exclude>**/model/**</exclude>
                    <exclude>**/item/**</exclude>
                </excludes>
            </configuration>

Also another way to exclude lombok generated classes since jacoco 0.8.0 and lombok 1.16.14.

Luckily, beginning with version 0.8.0, Jacoco can detect, identify and ignore Lombok-generated code. The only thing you as the developer have to do is to create a file named lombok.config in your directory’s root and set the following flag:

lombok.addLombokGeneratedAnnotation = true

This adds the annotation lombok.@Generated to the relevant methods, classes and fields. Jacoco is aware of this annotation and will ignore that annotated code.

Please keep in mind that you require at least version 0.8.0 of Jacoco and v1.16.14 of Lombok.