I am trying to get Jenkins to respect the jacoco code coverage configurations from the pom.xml instead of the configurations excplicitly set on the Jenkins code coverage plugin UI.
If I mention exclusions explicitly on the jacoco code coverage plugin UI, it is respected. But this does not seem to be feasible for more number of different projects which may have different configurations(exclusions, inclusions, coverage criteria).
The below jacoco snippet in pom.xml is respected when I run this locally using mvn clean install
. The code coverage report generated excludes the exclusions.
Any suggestions on how to make the coverage report generated on jenkins respect the exclusions from my pom.xml ?
Jacoco configurations respected from Jenkins code coverage UI
The goal mentioned in the jenkins configuration page is clean -U source:jar install -Pbundle
.
I tried removing the jacoco code coverage report from Jenkins configuration post-build actions thinking that it may respect the configurations in pom.xml but that ended up not generating the coverage report itself.
Snippet of jacoco from pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<!-- Sets the VM argument line used when unit tests are run. -->
<argLine>${surefireArgLine}</argLine>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.basedir}/target/jacoco.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<configuration>
<excludes>
<exclude>com/package/subpackage1/subpackage2/server/config/*.class</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the name of the property containing the settings for JaCoCo
runtime agent. -->
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>jacoco-site</id>
<phase>test</phase>
<goals>
<goal>report</goal>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>PACKAGE</element>
<limits>
<limit>
<counter>CLASS</counter>
<value>COVEREDRATIO</value>
<minimum>50%</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>