0

I've got a pom.xml that looks roughly like this:

<plugin>
  <groupId>org.jacoco</groupId>
  <artifactId>jacoco-maven-plugin</artifactId>
  <version>0.8.1</version>
  <configuration>
    <includes>
      <include>my/package/path/**/*</include>
    </includes>
  </configuration>
  <!-- more stuff -->
</plugin>

When I run my unit tests then call mvn jacoco:report locally on my laptop, everything is fine, and only the stuff in my.package.path is included. My coverage is 86%. However, when I let Jenkins run the unit tests, using the same commands, then call jacoco(execPattern:'target/jacoco.exec') in my Jenkinsfile, I end up with all code included in the report attached to the build, so my coverage ends up being 2% because I didn't write tests for a bunch of 3rd party libraries.

How do I fix this?

ewok
  • 20,148
  • 51
  • 149
  • 254

2 Answers2

0

You may exclude the 3rd party packages:

<excludes><!-- Exclude class from test coverage -->
    <exclude>**/*com/3rdparty/path/*</exclude>
</excludes>
Pete T
  • 456
  • 2
  • 8
  • doesn't resolve the issue. If jenkins isn't picking up the inclusion pattern, why would it pick up an exclusion pattern? – ewok Jun 25 '18 at 20:59
  • There are a couple of ways to exclude packages. Check the link here, see any answers would solve your problem: https://stackoverflow.com/questions/27799419/maven-jacoco-configuration-exclude-classes-packages-from-report-not-working – Pete T Jun 25 '18 at 21:05
  • 1
    all of these answers depend on maven and the pom.xml file. My problem relates to Jenkins seemingly not using that file. – ewok Jun 25 '18 at 21:07
  • You answered your own question. In that case, you may need to change the Jacoco configuration in Jenkins. https://stackoverflow.com/questions/42265838/how-to-have-code-coverage-in-jenkins-with-jacoco-and-multiple-modules – Pete T Jun 25 '18 at 21:10
0

I was able to solve it by using the inclusionPattern parameter in the call to jacoco:

jacoco(execPattern: 'target/jacoco.exec',inclusionPattern: 'my/package/path/**/*')
ewok
  • 20,148
  • 51
  • 149
  • 254