title: Why does Jacoco report show different coverages on consecutive test runs?
body: <p>I just added JaCoCo code coverage with <code>jacoco-maven-plugin</code> to a Quarkus application using <code>quarkus-junit5</code> and <code>maven-surefire-plugin</code> for unit testing.</p>
  <p>JaCoco reports are there when I run <code>mvn clean verify</code> but I noticed that when I run them again <strong>I get another coverage</strong>. Most of the time the coverage report <strong>doesn't include lines which are definetly covered by the unit tests</strong>.</p>
  <p>I know that the line coverage actually is at <strong>84%</strong>. IntelliJ IDEA coverage runner shows this one and also JaCoCo runner one time managed to show that one.</p>
  <p>But most of the time JaCoCo report shows a much lower line coverage at <strong>20%</strong> or <strong>30%</strong>.</p>
  <p>I am running JaCoCo in instrumentation offline mode as on-the-fly mode interfered with Quarkus.</p>
  <p>This is my set up:</p>
  <p>JaCoCo Agent dependency:</p>
  <pre><code>&lt;dependency&gt;
    &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
    &lt;artifactId&gt;org.jacoco.agent&lt;/artifactId&gt;
    &lt;classifier&gt;runtime&lt;/classifier&gt;
    &lt;scope&gt;test&lt;/scope&gt;
    &lt;version&gt;${jacoco.version}&lt;/version&gt;
  &lt;/dependency&gt;
  </code></pre>
  <p>JaCoCo plugin:</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
      &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
      &lt;version&gt;${jacoco.version}&lt;/version&gt;
      &lt;executions&gt;
          &lt;execution&gt;
              &lt;goals&gt;
                  &lt;goal&gt;instrument&lt;/goal&gt;
                  &lt;goal&gt;restore-instrumented-classes&lt;/goal&gt;
                  &lt;goal&gt;report&lt;/goal&gt;
              &lt;/goals&gt;
          &lt;/execution&gt;
      &lt;/executions&gt;
  &lt;/plugin&gt;
  
  </code></pre>
  <p>Surefire plugin:</p>
  <pre><code>&lt;plugin&gt;
      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
      &lt;version&gt;3.0.0-M5&lt;/version&gt;
      &lt;configuration&gt;
          &lt;systemPropertyVariables&gt;
              &lt;jacoco-agent.destfile&gt;${project.build.directory}/jacoco.exec&lt;/jacoco-agent.destfile&gt;
              &lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager&lt;/java.util.logging.manager&gt;
              &lt;maven.home&gt;${maven.home}&lt;/maven.home&gt;
              &lt;hibernate.search.backend.directory.type&gt;local-heap&lt;/hibernate.search.backend.directory.type&gt;
          &lt;/systemPropertyVariables&gt;
      &lt;/configuration&gt;
  &lt;/plugin&gt;
  
  </code></pre>
  <p>In case you need to know more, the pom.xml:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot;?&gt;
      &lt;project
          xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
          xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 
          https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;
          xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;artifactId&gt;backend&lt;/artifactId&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
  
          &lt;org.mapstruct.version&gt;1.4.2.Final&lt;/org.mapstruct.version&gt;
          &lt;jacoco.version&gt;0.8.7&lt;/jacoco.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-resteasy&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-smallrye-health&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-junit5&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.assertj&lt;/groupId&gt;
              &lt;artifactId&gt;assertj-core&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.exparity&lt;/groupId&gt;
              &lt;artifactId&gt;hamcrest-date&lt;/artifactId&gt;
              &lt;version&gt;2.0.7&lt;/version&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.rest-assured&lt;/groupId&gt;
              &lt;artifactId&gt;rest-assured&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-container-image-docker&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-hibernate-validator&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-hibernate-orm-panache&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-flyway&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-resteasy-jackson&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-jdbc-postgresql&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-micrometer&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.micrometer&lt;/groupId&gt;
              &lt;artifactId&gt;micrometer-registry-prometheus&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;io.quarkus&lt;/groupId&gt;
              &lt;artifactId&gt;quarkus-jdbc-h2&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;version&gt;1.18.16&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.apache.commons&lt;/groupId&gt;
              &lt;artifactId&gt;commons-lang3&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.search&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-search-mapper-orm&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.search&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-search-backend-lucene&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
              &lt;artifactId&gt;mapstruct&lt;/artifactId&gt;
              &lt;version&gt;${org.mapstruct.version}&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.mapstruct&lt;/groupId&gt;
              &lt;artifactId&gt;mapstruct-processor&lt;/artifactId&gt;
              &lt;version&gt;${org.mapstruct.version}&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
              &lt;artifactId&gt;org.jacoco.agent&lt;/artifactId&gt;
              &lt;classifier&gt;runtime&lt;/classifier&gt;
              &lt;scope&gt;test&lt;/scope&gt;
              &lt;version&gt;${jacoco.version}&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.jacoco&lt;/groupId&gt;
                  &lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;${jacoco.version}&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;instrument&lt;/goal&gt;
                              &lt;goal&gt;restore-instrumented-classes&lt;/goal&gt;
                              &lt;goal&gt;report&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.jboss.jandex&lt;/groupId&gt;
                  &lt;artifactId&gt;jandex-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.0.8&lt;/version&gt;
                  &lt;executions&gt;
                      &lt;execution&gt;
                          &lt;id&gt;make-index&lt;/id&gt;
                          &lt;goals&gt;
                              &lt;goal&gt;jandex&lt;/goal&gt;
                          &lt;/goals&gt;
                      &lt;/execution&gt;
                  &lt;/executions&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.8.1&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;parameters&gt;true&lt;/parameters&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                  &lt;version&gt;3.0.0-M5&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;systemPropertyVariables&gt;
                          &lt;jacoco-agent.destfile&gt;${project.build.directory}/jacoco.exec&lt;/jacoco-agent.destfile&gt;
                          &lt;java.util.logging.manager&gt;org.jboss.logmanager.LogManager&lt;/java.util.logging.manager&gt;
                          &lt;maven.home&gt;${maven.home}&lt;/maven.home&gt;
                          &lt;hibernate.search.backend.directory.type&gt;local-heap&lt;/hibernate.search.backend.directory.type&gt;
                      &lt;/systemPropertyVariables&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  <p>I would appreciate if someone has an idea what is the reason for this behaviour and could help me.</p>
  <p>In case you advise me to use the <code>quarkus-jacoco</code> extension. I tried this one by removing <code>jacoco-maven-plugin</code> and adding the <code>quarkus-jacoco</code> extension, but then I run into another problem after executing <code>mvn clean verify</code>:</p>
  <pre><code>Caused by: io.quarkus.builder.BuildException:
  Build failure: Build failed due to errors
          [error]: Build step io.quarkus.jacoco.deployment.JacocoProcessor#transformerBuildItem threw an exception: java.lang.NoClassDefFoundError: io/quarkus/deployment/builditem/BytecodeTransformerBuildItem$Builder
          at io.quarkus.jacoco.deployment.JacocoProcessor.transformerBuildItem(JacocoProcessor.java:71)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:566)
          at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:972)
          at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
          at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
          at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:2046)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1578)
          at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1452)
          at java.base/java.lang.Thread.run(Thread.java:834)
          at org.jboss.threads.JBossThread.run(JBossThread.java:479)
  Caused by: java.lang.ClassNotFoundException: io.quarkus.deployment.builditem.BytecodeTransformerBuildItem$Builder
          at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
          at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
          at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
          at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:412)
          at io.quarkus.bootstrap.classloading.QuarkusClassLoader.loadClass(QuarkusClassLoader.java:365)
          ... 13 more
  </code></pre>