javaquarkusjacocojacoco-plugin

How to configure Jacoco Gradle Plugin for Quarkus Tests (@QuarkusTest)?


I've got a problem with the JaCoCo configuration in combination with tests annotated with @QuarkusTest. We are using Quarkus 3.0.1.final

I'm using Gradle 7.5.1 and the JaCoCo Plugin 0.8.9. In our project we have the following configuration.

For each test set we want to generate a separate *.exec file and use it to generate our JaCoCo test report in xml format.

The following task configuration was used to generate the report:

jacoco {
  toolVersion = jacocoVersion
}

jacocoTestReport {
  mustRunAfter quarkusIntTest
  getExecutionData().setFrom(fileTree(buildDir).include("/jacoco/*.exec"))
  reports {
    xml.required = true
  }
}

After executing the tests and report generation with the command

./gradlew clean quarkusIntTest jacocoTestReport -x test

the quarkusIntTest.exec file is generated successfully.

However, it can't be used for the report as the following errors are printed:

> Task :app:jacocoTestReport
[ant:jacocoReport] Classes in bundle 'app' do not match with execution data. For report generation the same class files must be used as at runtime.
[ant:jacocoReport] Execution data for class com/org/app/rules/configuration/SampleRuleConfiguration does not match.
[ant:jacocoReport] Execution data for class com/org/app/sql/flyway/FlywayLifecycle does not match.
[ant:jacocoReport] Execution data for class com/org/app/config/TenantConfigProvider does not match.
...

Normally, this indicates that the tests were executed with a different java version than the report. Not sure how this miss match can happen in this case as the same java JDK should be used here for both tasks. Any idea how this issue can be solved?

I'm using Java 17

openjdk version "17.0.6" 2023-01-17 LTS
OpenJDK Runtime Environment Corretto-17.0.6.10.1 (build 17.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-17.0.6.10.1 (build 17.0.6+10-LTS, mixed mode, sharing)

Additionally, I've tried to use the JaCoCo extension to let Quarkus generate the code coverage files. However, the extension did not create any report at all. That might be caused by missing @QuarkusTests in the test source.


Solution

  • I was able to generate the *.exec file with the quarkus extention by changing the dependency scope to testImplementation "io.quarkus:quarkus-jacoco". I was previously using integrationTestImplementation "io.quarkus:quarkus-jacoco" as I don't have any @QuarkusTest in the test sources.

    For now I disabled the quarkus report generation (quarkus.jacoco.report=false) and I'm using the gradle plugin to generate the jacoco report using the integrationTest.exec (generated by the quarkus extension) and test.exec (generated by the jacoco gradle plugin) which is working fine.