英文:
Jacoco instrumentation error for Kotlin data class files
问题
我有一个Kotlin项目,目前在构建时显示了许多关于Jacoco的错误堆栈跟踪。通过更多的调查,我发现其中许多与数据类有关。例如对于类似以下的代码:
data class FooDTO(val a: String, val b: String)
我得到类似以下的错误信息:
java.lang.instrument.IllegalClassFormatException: Error while instrumenting path/to/FooDtoMethodAccess with JaCoCo 0.8.10.202304240956/8ea9668.
...
这是我的jacoco插件配置:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
如何摆脱这些错误消息?
英文:
I have a kotlin project that currently in the build time is showing a lot of error stack traces regarding Jacoco. By more investigation I found that a lot of them are regarding data classes. For example for something like:
data class FooDTO(val a: String, val b: String)
I am getting something like:
java.lang.instrument.IllegalClassFormatException: Error while instrumenting path/to/FooDtoMethodAccess with JaCoCo 0.8.10.202304240956/8ea9668.
at org.jacoco.agent.rt.internal_4a7f17c.CoverageTransformer.transform(CoverageTransformer.java:94)
at sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:428)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.esotericsoftware.reflectasm.AccessClassLoader.defineClass(AccessClassLoader.java:73)
at com.esotericsoftware.reflectasm.AccessClassLoader.defineAccessClass(AccessClassLoader.java:57)
at com.esotericsoftware.reflectasm.MethodAccess.get(MethodAccess.java:276)
at com.coxautodev.graphql.tools.MethodFieldResolverDataFetcher.<init>(MethodFieldResolver.kt:131)
at com.coxautodev.graphql.tools.MethodFieldResolver.createDataFetcher(MethodFieldResolver.kt:98)
at com.coxautodev.graphql.tools.SchemaParser$createObject$$inlined$forEach$lambda$1.apply(SchemaParser.kt:126)
at com.coxautodev.graphql.tools.SchemaParser$createObject$$inlined$forEach$lambda$1.apply(SchemaParser.kt:46)
at graphql.schema.GraphQLObjectType$Builder.field(GraphQLObjectType.java:207)
at com.coxautodev.graphql.tools.SchemaParser.createObject(SchemaParser.kt:124)
at com.coxautodev.graphql.tools.SchemaParser.parseSchemaObjects(SchemaParser.kt:85)
at com.coxautodev.graphql.tools.SchemaParser.makeExecutableSchema(SchemaParser.kt:109)
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration.graphQLSchema(GraphQLJavaToolsAutoConfiguration.java:65)
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$6059daa9.CGLIB$graphQLSchema$0(<generated>)
at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$6059daa9$$FastClassBySpringCGLIB$$8a2c10eb.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331)
06/07/2023 13:10:02 at com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration$$EnhancerBySpringCGLIB$$6059daa9.graphQLSchema(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at
This is my jacoco plugine configuration:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.10</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
How can I get rid of those error messages?
答案1
得分: 0
所以我发现了问题所在。这些文件并不是确切的数据类,而是可能由GraphQL自动生成的,名称以MethodAccess结尾。要摆脱它们,您可以轻松地从Jacoco中排除它们:
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<excludes>
<exclude>*MethodAccess</exclude>
</excludes>
</configuration>
</execution>
英文:
So I found out what is the problem. These files are not exactly data classes, but they are auto generated probably by graphQL and the names ends with MethodAccess. To get rid of it you can easily exclude them from Jacoco:
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<excludes>
<exclude>*MethodAccess</exclude>
</excludes>
</configuration>
</execution>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论