Search code examples
javamavenjacocojacoco-maven-plugin

How to set jacoco coverage percentage to 60% at child's pom?


Can some one tell me how to set Jacoco code coverage to a certain percentage in Child's POM. I have a parent dependency which is expecting 80% coverage. I need to limit that to 60% in my child project. I am setting 0.600 under child's pom properties. But this is not overriding the parent's coverage goal which is 80%. Any comments are appreciated..

<jacoco.percentage.instruction>0.600</jacoco.percentage.instruction>

Solution

  • The key is we cannot override just properties of Jacoco. I have copied the below parent's pom plug in to my project and I have updated the minimum covered ratio to 60% where it was 80% in parent's pom. This is working for me.

    <plugin>
       <groupId>org.jacoco</groupId>
       <artifactId>jacoco-maven-plugin</artifactId>
       <version>0.8.2</version>
       <executions>
          <execution>
             <id>default-check</id>
             <goals>
                <goal>check</goal>
             </goals>
             <configuration>
                <rules>
                   <rule>
                      <limits>
                         <limit>
                            <counter>INSTRUCTION</counter>
                            <minimum>60.0%</minimum>
                         </limit>
                      </limits>
                   </rule>
                </rules>
             </configuration>
          </execution>
          <execution>
             <id>default-audit-check</id>
             <goals>
                <goal>check</goal>
             </goals>
             <configuration>
                <haltOnFailure>false</haltOnFailure>
                <rules>
                   <rule>
                      <limits>
                         <limit>
                            <counter>INSTRUCTION</counter>
                            <minimum>60.0%</minimum>
                         </limit>
                      </limits>
                   </rule>
                </rules>
             </configuration>
          </execution>
          <execution>
             <id>default-prepare-agent</id>
             <goals>
                <goal>prepare-agent</goal>
             </goals>
             <configuration>
                <propertyName>jacoco.surefire.argLine</propertyName>
             </configuration>
          </execution>
       </executions>
    </plugin>