gpt4 book ai didi

maven - 雅 cocoa - "Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline"

转载 作者:行者123 更新时间:2023-12-02 17:50:42 27 4
gpt4 key购买 nike

尝试使用离线检测通过 jacoco 获取覆盖范围(无法使用即时检测:由于 powermock 测试用例)的 Maven 项目。将 jacocoagent.jar 添加到 Surefire 插件的类路径中,如下所示。将“org.jacoco.agent-0.7.7.201606060606-runtime.jar”(来自本地maven存储库)重命名为“jacocoagent.jar”并将其保存在该pom.xml所在的同一文件夹中。我点击下面的内容即使将其添加到类路径后也会出现异常。

pom.xml 的片段(surefire - 插件配置)

       <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkmode>once</forkmode>
<additionalClasspathElements>
<additionalClasspathElement>jacocoagent.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>

控制台上出现异常:

#############
Number of foreign imports: 1
import: Entry[import from realm ClassRealm[maven.api, parent: null]]

-----------------------------------------------------

at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:166)
... 21 more
Caused by: java.lang.NoClassDefFoundError: org/jacoco/agent/rt/internal_6da5971/Offline
at com.cisco.ise.ups.modelframework.hibernate.OracleNamingStrategy.$jacocoInit(OracleNamingStrategy.java)
at com.cisco.ise.ups.modelframework.hibernate.OracleNamingStrategy.<clinit>(OracleNamingStrategy.java)
at sun.misc.Unsafe.ensureClassInitialized(Native Method)
at sun.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)
at sun.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:142)
at java.lang.reflect.Field.acquireFieldAccessor(Field.java:1082)
at java.lang.reflect.Field.getFieldAccessor(Field.java:1063)
at java.lang.reflect.Field.get(Field.java:387)
at com.cisco.ise.ups.build.WorkflowRunnerMojo.namingStrategyInstance(WorkflowRunnerMojo.java:335)
at com.cisco.ise.ups.build.WorkflowRunnerMojo.setupWorkflowEnvironment(WorkflowRunnerMojo.java:514)
at com.cisco.ise.ups.build.WorkflowRunnerMojo.execute(WorkflowRunnerMojo.java:816)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
... 33 more
[ERROR]
###############

遵循的步骤:

  1. “mvn 编译”。
  2. “mvn org.jacoco:jacoco-maven-plugin:仪器”
  3. “mvn test” - 此步骤引发异常。

请告诉我如何消除这个异常?这是添加类路径的正确位置吗? (在 Surefire 插件中)或者应该在某个地方指定??

谢谢。

最佳答案

surefire 插件上的类路径内容不是必需的。您需要向每个具有测试的模块添加依赖项,如下所示:

<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.agent</artifactId>
<classifier>runtime</classifier>
<scope>test</scope>
<version>${your.jacoco.version}</version>
</dependency>

确保您没有错过“分类器”部分,否则它将无法工作。

Full example from PowerMock project

关于maven - 雅 cocoa - "Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40067455/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com