项目升级OpenJDK11所遇到的各种坑之jacoco-maven-plugin

升级OpenJDK11之后,本身项目中有用到jacoco-maven-plugin进行代码覆盖检查。但是当进行maven install的时候总会报如下的错误:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project websocket-proxy-java-service: Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?

刚开始一脸懵逼啊,看了下控制台的日志,往上滑了一下,看到一些报错的信息

Exception in thread "main" java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
	at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
Caused by: java.lang.RuntimeException: Class java/util/UUID could not be instrumented.
	at org.jacoco.agent.rt.internal_e5875b2.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
	at org.jacoco.agent.rt.internal_e5875b2.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
	at org.jacoco.agent.rt.internal_e5875b2.PreMain.createRuntime(PreMain.java:55)
	at org.jacoco.agent.rt.internal_e5875b2.PreMain.premain(PreMain.java:47)
	... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
	at java.base/java.lang.Class.getField(Class.java:2000)
	at org.jacoco.agent.rt.internal_e5875b2.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
	... 9 more

此刻更是一脸懵逼啊,小菜鸟没遇到过这样的问题啊,于是Google各通找,最后在一些国外的网站上找到许多出现此错误的人,原来我用的jacoco-maven-plugin插件的版本只支持到java9,所以去Maven仓库找了最新的版本,然后替换了项目里的旧版本,就成功解决了这个问题。
最新的版本如下:

            
            org.jacoco
            jacoco-maven-plugin
                0.8.2
            

至此此问题成功解决,小小记录一下~开心!

你可能感兴趣的:(突发问题,新知识的学习)