Error when executing tests in java maven jacoco: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

huangapple go评论160阅读模式
英文:

Error when executing tests in java maven jacoco: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

问题

以下是翻译好的部分:

在执行Java Maven Jacoco中的测试时出现错误:无法执行目标org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

早上好。我正在进行一个Maven项目,我使用NetBeans编写Java代码。当我尝试运行一个测试文件时,我收到以下错误消息:

切换到目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios; "JAVA_HOME=C:\\Program Files\\Java\\jdk-14" cmd /c ""C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven\\bin\\mvn.cmd" -Dtest=com.mycompany.erro_testes_unitarios.NewMainTest -Dmaven.ext.class.path="C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 test-compile surefire:test"
正在扫描项目...
                                                                    
------------------------------------------------------------------------
正在构建 erro_testes_unitarios 1.0-SNAPSHOT
------------------------------------------------------------------------

--- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default) @ erro_testes_unitarios ---
argLine 设置为 -javaagent:C:\\Users\\ruimi\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\
切换到目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios; "JAVA_HOME=C:\\Program Files\\Java\\jdk-14" cmd /c ""C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven\\bin\\mvn.cmd" -Dtest=com.mycompany.erro_testes_unitarios.NewMainTest -Dmaven.ext.class.path="C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar" -Dfile.encoding=UTF-8 test-compile surefire:test"
正在扫描项目...
------------------------------------------------------------------------
正在构建 erro_testes_unitarios 1.0-SNAPSHOT
------------------------------------------------------------------------
--- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default) @ erro_testes_unitarios ---
argLine 设置为 -javaagent:C:\\Users\\ruimi\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.7.201606060606\\org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=C:\\Users\\ruimi\\Documents\\NetBeansProjects\\erro_testes_unitarios\\target\\jacoco.exec
--- maven-resources-plugin:2.6:resources (default-resources) @ erro_testes_unitarios ---
使用 'UTF-8' 编码复制过滤后的资源。
跳过不存在的资源目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\main\resources
--- maven-compiler-plugin:3.1:compile (default-compile) @ erro_testes_unitarios ---
无需编译 - 所有类都是最新的
--- maven-resources-plugin:2.6:testResources (default-testResources) @ erro_testes_unitarios ---
使用 'UTF-8' 编码复制过滤后的资源。
跳过不存在的资源目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\test\resources
--- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ erro_testes_unitarios ---
无需编译 - 所有类都是最新的
--- maven-surefire-plugin:2.12.4:test (default-cli) @ erro_testes_unitarios ---
Surefire 报告目录:C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\target\surefire-reports
-------------------------------------------------------
测试
-------------------------------------------------------
"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:564)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513)
at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525)
异常原因:java.lang.RuntimeException: 无法对类 java/util/UUID 进行插装。
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(PreMain.java:47)
... 6 more
异常原因:java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:2013)
at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more
*** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at JPLISAgent.c line: 422
本机方法中的致命错误:处理 -javaagent 失败,processJavaStart 失败
结果:
运行的测试数:0,失败:0,错误:0,跳过:0
------------------------------------------------------------------------
构建失败
------------------------------------------------------------------------
总时间:2.899 秒
完成于:2020-04-10T13:14:06+01:00
最终内存:11M/47M
------------------------------------------------------------------------
无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-cli) 项目 erro_testes_unitarios 上的执行 default-cli 失败:分叉的 VM 在退出时没有正常说再见。VM 崩溃或调用 System.exit?-> [帮助 1]
要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。
使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。
有关错误和可能解决方案的更多信息,请阅读以下文章:
[帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
.7.7.201606060606\\org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=C:\\Users\\ruimi\\Documents\\NetBeansProjects\\erro_testes_unitarios\\target\\jacoco.exec --- maven-resources-plugin:2.6:resources (default-resources) @ erro_testes_unitarios --- 使用 'UTF-8' 编码复制过滤后的资源。 跳过不存在的资源目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\main\resources --- maven-compiler-plugin:3.1:compile (default-compile) @ erro_testes_unitarios --- 无需编译 - 所有类都是最新的 --- maven-resources-plugin:2.6:testResources (default-testResources) @ erro_testes_unitarios --- 使用 'UTF-8' 编码复制过滤后的资源。 跳过不存在的资源目录 C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\test\resources --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ erro_testes_unitarios --- 无需编译 - 所有类都是最新的 --- maven-surefire-plugin:2.12.4:test (default-cli) @ erro_testes_unitarios --- Surefire 报告目录:C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\target\surefire-reports ------------------------------------------------------- 测试 ------------------------------------------------------- "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:564) at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:513) at java.instrument/sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:525) 异常原因:java.lang.RuntimeException: 无法对类 java/util/UUID 进行插装。 at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140) at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101) at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(PreMain.java:55) at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(PreMain.java:47) ... 6 more 异常原因:java.lang.NoSuchFieldException: $jacocoAccess at java.base/java.lang.Class.getField(Class.java:2013) at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138) ... 9 more *** java.lang.instrument ASSERTION FAILED ***: "result" with message agent load/premain call failed at JPLISAgent.c line: 422 本机方法中的致命错误:处理 -javaagent 失败,processJavaStart 失败 结果: 运行的测试数:0,失败:0,错误:0,跳过:0 ------------------------------------------------------------------------ 构建失败 ------------------------------------------------------------------------ 总时间:2.899 秒 完成于:2020-04-10T13:14:06+01:00 最终内存:11M/47M ------------------------------------------------------------------------ 无法执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-cli) 项目 erro_testes_unitarios 上的执行 default-cli 失败:分叉的 VM 在退出时没有正常说再见。VM 崩溃或调用 System.exit?-> [帮助 1] 要查看错误的完整堆栈跟踪,请使用 -e 开关重新运行 Maven。 使用 -X 开关重新运行 Maven 以启用完整的调试日志记录。 有关错误和可能解决方案的更多信息,请阅读以下文章: [帮助 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

这是我的 pom.xml 文件:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
   

<details>
<summary>英文:</summary>

Error when executing tests in java maven jacoco: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test

Good Morning. I am carrying out a Maven project and I use NetBeans to write Java code. When I try to run a test file, I get this error:


    cd C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios; &quot;JAVA_HOME=C:\\Program Files\\Java\\jdk-14&quot; cmd /c &quot;\&quot;C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven\\bin\\mvn.cmd\&quot; -Dtest=com.mycompany.erro_testes_unitarios.NewMainTest -Dmaven.ext.class.path=\&quot;C:\\Program Files\\netbeans 11.3 tenativa 1000\\NetBeans-11.3\\netbeans\\java\\maven-nblib\\netbeans-eventspy.jar\&quot; -Dfile.encoding=UTF-8 test-compile surefire:test&quot;
    Scanning for projects...
                                                                        
    ------------------------------------------------------------------------
    Building erro_testes_unitarios 1.0-SNAPSHOT
    ------------------------------------------------------------------------

    --- jacoco-maven-plugin:0.7.7.201606060606:prepare-agent (default) @ erro_testes_unitarios ---
    argLine set to -javaagent:C:\\Users\\ruimi\\.m2\\repository\\org\\jacoco\\org.jacoco.agent\\0.7.7.201606060606\\org.jacoco.agent-0.7.7.201606060606-runtime.jar=destfile=C:\\Users\\ruimi\\Documents\\NetBeansProjects\\erro_testes_unitarios\\target\\jacoco.exec
    
    --- maven-resources-plugin:2.6:resources (default-resources) @ erro_testes_unitarios ---
    Using &#39;UTF-8&#39; encoding to copy filtered resources.
    skip non existing resourceDirectory C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\main\resources
    
    --- maven-compiler-plugin:3.1:compile (default-compile) @ erro_testes_unitarios ---
    Nothing to compile - all classes are up to date
    
    --- maven-resources-plugin:2.6:testResources (default-testResources) @ erro_testes_unitarios ---
    Using &#39;UTF-8&#39; encoding to copy filtered resources.
    skip non existing resourceDirectory C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\src\test\resources
    
    --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ erro_testes_unitarios ---
    Nothing to compile - all classes are up to date
    
    --- maven-surefire-plugin:2.12.4:test (default-cli) @ erro_testes_unitarios ---
    Surefire report directory: C:\Users\ruimi\Documents\NetBeansProjects\erro_testes_unitarios\target\surefire-reports

    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------

    Exception in thread &quot;main&quot; 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:564)
    	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_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
    	at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
    	at org.jacoco.agent.rt.internal_6da5971.PreMain.createRuntime(PreMain.java:55)
    	at org.jacoco.agent.rt.internal_6da5971.PreMain.premain(PreMain.java:47)
    	... 6 more
    Caused by: java.lang.NoSuchFieldException: $jacocoAccess
    	at java.base/java.lang.Class.getField(Class.java:2013)
    	at org.jacoco.agent.rt.internal_6da5971.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
    	... 9 more
    *** java.lang.instrument ASSERTION FAILED ***: &quot;result&quot; with message agent load/premain call failed at JPLISAgent.c line: 422
    FATAL ERROR in native method: processing of -javaagent failed, processJavaStart failed
    
    Results :
    
    Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

    ------------------------------------------------------------------------
    BUILD FAILURE
    ------------------------------------------------------------------------

    Total time: 2.899 s
    Finished at: 2020-04-10T13:14:06+01:00
    Final Memory: 11M/47M

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

    Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-cli) on project erro_testes_unitarios: Execution default-cli of goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test failed: The forked VM terminated without saying properly goodbye. VM crash or System.exit called ? -&gt; [Help 1]
    
    To see the full stack trace of the errors, re-run Maven with the -e switch.
    Re-run Maven using the -X switch to enable full debug logging.
    
    For more information about the errors and possible solutions, please read the following articles:
    [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException


Here is my pom.xml file: 

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>erro_testes_unitarios</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>14</maven.compiler.source>
<maven.compiler.target>14</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

    &lt;/plugins&gt;
&lt;/build&gt;

</project>


Can you help me with this?
Thank you all for your availability!
</details>
# 答案1
**得分**: 14
显然,您正在使用JDK 14作为开发和测试环境。您可以检查它。转至 `帮助 -> 关于 -> Java`。集成的Maven和Maven中的所有插件使用与NetBeans作为执行环境使用的JDK版本。
Jacoco在0.8.5 [版本][1] 中增加了对JDK 14的实验性支持:
&gt; - JaCoCo现在正式支持Java 13
&gt; - 对 **Java 14** 类文件的实验性支持 (GitHub #897)。
&gt; - Kotlin编译器为带有默认参数的开放函数添加的分支在报告生成期间被过滤掉 (GitHub #887)。
您可以将插件版本更改为0.8.5:
...
&lt;groupId&gt;org.jacoco&lt;/groupId&gt; 
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt; 
&lt;version&gt;0.8.5&lt;/version&gt;
... 
0.7.7 版本支持JDK 8或更早版本。因此,如果您想使用插件的0.7.7版本,您可以使用JDK 8。有关为NetBeans设置JDK版本的方法,请参阅[问题][2]。此外,使用JDK 8时,您还应将 maven.compiler.source 和 maven.compiler.target 更改为 1.8。
[1]: https://github.com/jacoco/jacoco/releases/tag/v0.8.5
[2]: https://stackoverflow.com/q/6950960/5681468
<details>
<summary>英文:</summary>
Apparently, you are using JDK 14 as your dev and test environment. You can check it. Go to `Help -&gt; About -&gt; Java.` Integrated Maven and all plugins within Maven uses the JDK version that NetBeans using as an exec environment.
Jacoco added experimental support for JDK 14 only in 0.8.5 [version][1]:
&gt;  - JaCoCo now officially supports Java 13
&gt;  - Experimental support for **Java 14** class files (GitHub #897).
&gt;  - Branches added by the Kotlin compiler for open functions with default arguments are filtered out during generation of report (GitHub #887).
You can change the plugin version to 0.8.5:
...
&lt;groupId&gt;org.jacoco&lt;/groupId&gt; 
&lt;artifactId&gt;jacoco-maven-plugin&lt;/artifactId&gt; 
&lt;version&gt;0.8.5&lt;/version&gt;
... 
The 0.7.7 version supports JDK 8 or earlier versions. So, if you want to use the 0.7.7 version of the plugin you can use JDK 8. For setting JDK version for NetBeans please see the [question][2]. Also with JDK 8 you should change maven.compiler.source and maven.compiler.target to 1.8
[1]: https://github.com/jacoco/jacoco/releases/tag/v0.8.5
[2]: https://stackoverflow.com/q/6950960/5681468
</details>

huangapple
  • 本文由 发表于 2020年4月10日 20:26:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/61140209.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定