我最近使用 Quarkus CLI(quarkus 更新)将 Quarkus 项目从版本 2.16 迁移到 3.6.4。更新过程很顺利,Maven包升级成功。
但是,当尝试使用 mvn quarkus:dev 运行项目时,我遇到了与 JaCoCo 相关的问题。日志表明存在以下问题: java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_4481564/Offline
13:46:03 ERROR [traceId=,spanId=] [io.qu.de.de.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
[error]: Build step io.quarkus.resteasy.reactive.common.deployment.ResteasyReactiveCommonProcessor#handleApplication threw an exception: java.lang.RuntimeException: Unable to handle class: tn.wecraft.bore.Application
at org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveScanner.scanForApplicationClass(ResteasyReactiveScanner.java:117)
at io.quarkus.resteasy.reactive.common.deployment.ResteasyReactiveCommonProcessor.handleApplication(ResteasyReactiveCommonProcessor.java:181)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:849)
at io.quarkus.builder.BuildContext.run(BuildContext.java:256)
at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2513)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1538)
at java.base/java.lang.Thread.run(Thread.java:842)
at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: java.lang.reflect.InvocationTargetException
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.jboss.resteasy.reactive.common.processor.scanning.ResteasyReactiveScanner.scanForApplicationClass(ResteasyReactiveScanner.java:99)
... 12 more
Caused by: java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_4481564/Offline
at tn.wecraft.bore.Application.$jacocoInit(Application.java)
at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:90)
at java.base/java.lang.invoke.ConstantBootstraps.makeConstant(ConstantBootstraps.java:72)
at java.base/java.lang.invoke.MethodHandleNatives.linkDynamicConstantImpl(MethodHandleNatives.java:337)
at java.base/java.lang.invoke.MethodHandleNatives.linkDynamicConstant(MethodHandleNatives.java:329)
at tn.wecraft.bore.Application.<init>(Application.java)
... 18 more
我已尝试调查该问题,但不确定如何解决。以下是我迄今为止采取的步骤:
验证 Quarkus 迁移后所有依赖项均已正确更新。 检查了我的 pom.xml 文件中的 JaCoCo 插件配置。 如果您能就如何解决 Quarkus 迁移后的 JaCoCo 问题提供任何指导或建议,我将不胜感激。谢谢!
附加信息:
迁移前的 Quarkus 版本:2.16 迁移后的 Quarkus 版本:3.6.4 pom.xml 中与 JaCoCo 配置相关的部分。
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jacoco</artifactId>
<scope>test</scope>
</dependency>
...
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<argLine>-Dquarkus.test.hang-detection-timeout=10s -Duser.language=en -Duser.region=FR</argLine>
<failIfNoTests>false</failIfNoTests>
<runOrder>random</runOrder>
<includes>
<include>**/*Test.java</include>
</includes>
<forkedProcessExitTimeoutInSeconds>30</forkedProcessExitTimeoutInSeconds>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/jacoco-ut.exec</jacoco-agent.destfile>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
<user.language>en</user.language>
<user.region>FR</user.region>
</systemPropertyVariables>
</configuration>
<executions>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!--suppress UnresolvedMavenProperty -->
<includes>
<include>**/*IT.java</include>
</includes>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/jacoco-it.exec
</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${maven-jacoco-plugin.version}</version>
<executions>
<execution>
<id>before-unit-test-execution</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco-ut.exec</destFile>
<propertyName>surefire.jacoco.args</propertyName>
<exclClassLoaders>*QuarkusClassLoader</exclClassLoaders>
</configuration>
</execution>
<execution>
<id>instrument-ut</id>
<goals>
<goal>instrument</goal>
</goals>
</execution>
<execution>
<id>restore-ut</id>
<goals>
<goal>restore-instrumented-classes</goal>
</goals>
</execution>
<execution>
<id>after-unit-test-execution</id>
<phase>pre-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-ut.exec</dataFile>
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut-coverage-report
</outputDirectory>
</configuration>
</execution>
<execution>
<id>after-integration-test-execution</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco-quarkus.exec</dataFile>
<outputDirectory>
${project.reporting.outputDirectory}/jacoco-it-coverage-report
</outputDirectory>
</configuration>
</execution>
<execution>
<id>merge-unit-and-integration</id>
<phase>post-integration-test</phase>
<goals>
<goal>merge</goal>
</goals>
<configuration>
<fileSets>
<fileSet>
<directory>${project.build.directory}</directory>
<includes>
<include>*.exec</include>
</includes>
</fileSet>
</fileSets>
<destFile>${project.build.directory}/merged.exec</destFile>
</configuration>
</execution>
<execution>
<id>create-merged-report</id>
<phase>post-integration-test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/merged.exec</dataFile>
<outputDirectory>
${project.reporting.outputDirectory}/jacoco-merged-test-coverage-report
</outputDirectory>
</configuration>
</execution>
<execution>
<id>check</id>
<phase>verify</phase>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<element>BUNDLE</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.coverage.min}</minimum>
</limit>
</limits>
</rule>
</rules>
<dataFile>${project.build.directory}/merged.exec</dataFile>
</configuration>
</execution>
</executions>
</plugin>
...
您能解决这个问题吗?我陷入了类似的困境。让我知道你是如何解决的