2

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>
Sunil
  • 101
  • 1
  • 10
  • you sure this is the jacoco plugin? the docs don't mention this property at all: https://www.eclemma.org/jacoco/trunk/doc/check-mojo.html - and the limit config looks quite different. or is this some own build property like here: https://automationrhapsody.com/automated-code-coverage-of-unit-tests-with-jacoco-and-maven/ ? you can always run your build with -X to see the plugin config or mvn help:effective-pom to figure out whats going on. worst case is add the complete plugin config into your pom – wemu Jun 14 '19 at 23:34
  • config aftr mvn effective-pom ` default-check check INSTRUCTION 80.0% ` – Sunil Jun 17 '19 at 18:37
  • That is what I can after running mvn effecitve-pom – Sunil Jun 17 '19 at 18:50
  • well, I would think that config is in some parent pom somewhere. if it is using a property make sure its the correct one. – wemu Jun 17 '19 at 18:55

1 Answers1

2

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>
SternK
  • 11,649
  • 22
  • 32
  • 46
Sunil
  • 101
  • 1
  • 10