Excluding files from jacoco for code coverage using Jenkins pipeline

114 Views Asked by At

I am using jacoco maven plugin for build and jacoco() & codecov in my JenkinsFile to report code coverage.

I have exceuded some file in the jacoco maven plugin. The exclusion works on the report generated by codecov but not for jacoco.

pom.xml

<plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco-maven-plugin.version}</version>
                <configuration>
                    <dataFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</dataFile>
                    <outputDirectory>${project.testresult.directory}/coverage/jacoco
                    </outputDirectory>
                    <excludes>
                        <exclude>**/*Constants.*</exclude>
                        <exclude>**/*Exception.*</exclude>
                        <exclude>**/*Logger.*</exclude>
                        <exclude>**/config/*</exclude>
                        <exclude>**/ConfigHandler.*</exclude>
                    </excludes>
                    <!-- Sets the path to the file which contains the execution data. -->
                    <destFile>${project.testresult.directory}/coverage/jacoco/jacoco.exec</destFile>
                </configuration>
                <executions>
                    <execution>
                        <id>prepare-agent</id>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

JenkinsFile

steps {
          sh 'mvn clean install'
          junit '**/surefire-reports/**/*.xml'
          jacoco()
          sh '''
            curl -Os https://uploader.codecov.io/latest/linux/codecov
            chmod +x codecov
            ./codecov -t ${CODECOV_TOKEN} -u ${URL} -C ${GIT_COMMIT_HASH}
            rm -f ./codecov || true
            '''
       }

Any idea why ?

Adding exclusions inside jacoco() works, but is there a way by which they can be picked up from plugin itself

0

There are 0 best solutions below