S3 Does Not Compile And Throws Io.quarkus.builder.BuildChainBuilder Cannot Be Cast To Class When Coverage Is Involved
Introduction
In this article, we will discuss an issue that arises when using the Quarkus framework with the AWS S3 extension and Jacoco coverage reports. The problem occurs when trying to compile the project with Quarkus version 3.21.3, and it is only present when including coverage reports as part of the build step. We will explore the error message, the possible causes, and the solutions to this issue.
Error Message
The error message is as follows:
java.lang.RuntimeException: java.lang.ClassCastException: class io.quarkus.builder.BuildChainBuilder cannot be cast to class io.quarkus.builder.BuildChainBuilder (io.quarkus.builder.BuildChainBuilder is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4e7095ac; io.quarkus.builder.BuildChainBuilder is in unnamed module of loader 'app')
at io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:611)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:706)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.ClassCastException: class io.quarkus.builder.BuildChainBuilder cannot be cast to class io.quarkus.builder.BuildChainBuilder (io.quarkus.builder.BuildChainBuilder is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4e7095ac; io.quarkus.builder.BuildChainBuilder is in unnamed module of loader 'app')
at io.quarkus.test.junit.TestBuildChainFunction$1.accept(TestBuildChainFunction.java:42)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:131)
at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:368)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:289)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:61)
at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:195)
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:578)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:628)
... 1 more
Possible Causes
The possible causes of this issue are:
- Quarkus version: The issue may be caused by the Quarkus version 3.21.3. Downgrading to Quarkus 3.21.2 resolves the issue.
- Jacoco coverage reports: The issue may be caused by the Jacoco coverage reports. When the coverage reports are included as part of the build step, the issue occurs.
- Maven module**: The issue may be caused by the separate Maven module "coverage" that aggregates all the various dependencies into one report and merges them together.
Solutions
The solutions to this issue are:
- Downgrade Quarkus version: Downgrade Quarkus to version 3.21.2 to resolve the issue.
- Separate build steps: Separate the build steps into two steps: one for running Jacoco and another for generating the coverage reports. This resolves the issue.
- Remove coverage reports: Remove the coverage reports from the build step to resolve the issue.
Conclusion
In conclusion, the issue of S3 not compiling and throwing a ClassCastException when coverage is involved is caused by the Quarkus version 3.21.3 and the Jacoco coverage reports. The solutions to this issue are to downgrade Quarkus to version 3.21.2, separate the build steps, or remove the coverage reports from the build step.
Maven Module Configuration
The Maven module configuration for the "coverage" module is as follows:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<executions>
<execution>
<id>jacoco-merge-all</id>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<fileSets>
<fileSet>
<directory>.</directory>
<includes>
<include>**/target/*.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
<execution>
<id>jacoco-report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<outputDirectory>target/site/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Q: What is the issue with Quarkus 3.21.3 and S3 extension?
A: The issue with Quarkus 3.21.3 and S3 extension is that it fails to compile with a ClassCastException when coverage reports are included as part of the build step.
Q: What is the error message?
A: The error message is as follows:
java.lang.RuntimeException: java.lang.ClassCastException: class io.quarkus.builder.BuildChainBuilder cannot be cast to class io.quarkus.builder.BuildChainBuilder (io.quarkus.builder.BuildChainBuilder is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4e7095ac; io.quarkus.builder.BuildChainBuilder is in unnamed module of loader 'app')
at io.quarkus.test.junit.QuarkusTestExtension.throwBootFailureException(QuarkusTestExtension.java:611)
at io.quarkus.test.junit.QuarkusTestExtension.interceptTestClassConstructor(QuarkusTestExtension.java:706)
at java.base/java.util.Optional.orElseGet(Optional.java:364)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
Caused by: java.lang.ClassCastException: class io.quarkus.builder.BuildChainBuilder cannot be cast to class io.quarkus.builder.BuildChainBuilder (io.quarkus.builder.BuildChainBuilder is in unnamed module of loader io.quarkus.bootstrap.classloading.QuarkusClassLoader @4e7095ac; io.quarkus.builder.BuildChainBuilder is in unnamed module of loader 'app')
at io.quarkus.test.junit.TestBuildChainFunction$1.accept(TestBuildChainFunction.java:42)
at io.quarkus.deployment.QuarkusAugmentor.run(QuarkusAugmentor.java:131)
at io.quarkus.runner.bootstrap.AugmentActionImpl.runAugment(AugmentActionImpl.java:368)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:289)
at io.quarkus.runner.bootstrap.AugmentActionImpl.createInitialRuntimeApplication(AugmentActionImpl.java:61)
at io.quarkus.test.junit.QuarkusTestExtension.doJavaStart(QuarkusTestExtension.java:195)
at io.quarkus.test.junit.QuarkusTestExtension.ensureStarted(QuarkusTestExtension.java:578)
at io.quarkus.test.junit.QuarkusTestExtension.beforeAll(QuarkusTestExtension.java:628)
... 1 more
Q: What are the possible causes of this issue?
A: The possible causes of this issue are:
- Quarkus version: The issue may be caused by the Quarkus version 3.21.3.
- Jacoco coverage reports: The issue may be caused by the Jacoco coverage reports.
- Maven module: The issue may be caused by the separate Maven module "coverage" that aggregates all the various dependencies into one report and merges them together.
Q: are the solutions to this issue?
A: The solutions to this issue are:
- Downgrade Quarkus version: Downgrade Quarkus to version 3.21.2 to resolve the issue.
- Separate build steps: Separate the build steps into two steps: one for running Jacoco and another for generating the coverage reports. This resolves the issue.
- Remove coverage reports: Remove the coverage reports from the build step to resolve the issue.
Q: What is the Maven module configuration for the "coverage" module?
A: The Maven module configuration for the "coverage" module is as follows:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.13</version>
<executions>
<execution>
<id>jacoco-merge-all</id>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<destFile>target/jacoco.exec</destFile>
<fileSets>
<fileSet>
<directory>.</directory>
<includes>
<include>**/target/*.exec</include>
</includes>
</fileSet>
</fileSets>
</configuration>
</execution>
<execution>
<id>jacoco-report-aggregate</id>
<phase>verify</phase>
<goals>
<goal>report-aggregate</goal>
</goals>
<configuration>
<outputDirectory>target/site/jacoco-aggregate</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
This configuration aggregates all the various dependencies into one report and merges them together.
Q: How can I resolve this issue?
A: To resolve this issue, you can try the following:
- Downgrade Quarkus to version 3.21.2.
- Separate the build steps into two steps: one for running Jacoco and another for generating the coverage reports.
- Remove the coverage reports from the build step.
By following these steps, you should be able to resolve the issue and successfully compile your project with Quarkus 3.21.3 and S3 extension.