gpt4 book ai didi

java - 如何修复Java中的 'Could not write standard input to Gradle Test Executor 1'错误

转载 作者:行者123 更新时间:2023-12-01 21:56:20 37 4
gpt4 key购买 nike

我正在尝试编译我的代码(在新分支上),但在修复和更新 build.gradle 后出现错误,但在运行该代码之前我的代码(在旧分支上)仍然有效。

所以我 checkout 主分支,我仍然收到该错误

这是我修复后的 build.gradle


apply plugin: 'java'
apply plugin: 'jacoco'

group 'com.quangha'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
mavenCentral()
}

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled false
}
}

check.dependsOn jacocoTestReport

我认为它仍然有效并且出现此错误

Could not write standard input to Gradle Test Executor 1.
java.io.IOException: The pipe is being closed
at java.base/java.io.FileOutputStream.writeBytes(Native Method)
at java.base/java.io.FileOutputStream.write(FileOutputStream.java:354)
at java.base/java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:81)
at java.base/java.io.BufferedOutputStream.flush(BufferedOutputStream.java:142)
at org.gradle.process.internal.streams.ExecOutputHandleRunner.forwardContent(ExecOutputHandleRunner.java:66)
at org.gradle.process.internal.streams.ExecOutputHandleRunner.run(ExecOutputHandleRunner.java:51)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
at java.base/java.lang.Thread.run(Thread.java:834)
> Task :test FAILED
---- IntelliJ IDEA coverage runner ----
sampling ...
include patterns:
exclude patterns:
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)
FATAL ERROR in native method: processing of -javaagent failed
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/lang/UnknownError could not be instrumented.
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:140)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:101)
at org.jacoco.agent.rt.internal_c13123e.PreMain.createRuntime(PreMain.java:55)
at org.jacoco.agent.rt.internal_c13123e.PreMain.premain(PreMain.java:47)
... 6 more
Caused by: java.lang.NoSuchFieldException: $jacocoAccess
at java.base/java.lang.Class.getField(Class.java:1999)
at org.jacoco.agent.rt.internal_c13123e.core.runtime.ModifiedSystemClassRuntime.createFor(ModifiedSystemClassRuntime.java:138)
... 9 more```

最佳答案

就我而言,问题是由 java 版本不匹配引起的。我的默认java(和项目的java)是1.8.x,而用户home中的gradle.properties中设置的java设置为java 11:
#这是Gradle本身将使用的Java安装
org.gradle.java.home=c:/tools/jdk-11.0.5
将 org.gradle.java.home 设置调整为指向 1.8 版本后,问题消失了。

关于java - 如何修复Java中的 'Could not write standard input to Gradle Test Executor 1'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57442936/

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