Gradle 构建在执行 :test 任务(junit 测试)时失败。 它给出了错误
Process 'Gradle Test Executor 1' finished with non-zero exit value 1
我正在 Eclipse 中的 java 项目中使用 gradle。 Gradle 1.12 和 Java 7。当在连接到数据库的类上运行测试时,似乎会发生问题。 奇怪的是,程序和测试作为 java 应用程序运行良好。 数据库连接没有问题,编译运行正确。 gradle 是否做了一些可能会扰乱其与外部数据库服务器连接方式的事情? 该问题可能与数据库无关,因此任何解决方案都值得赞赏。 我在网上和官方 gradle 网站上查看过,但没有任何帮助。 谢谢。
编辑
调试结果:
14:23:28.661 [DEBUG] [TestEventLogger]
14:23:28.661 [DEBUG] [TestEventLogger] Test Run PASSED
14:23:28.665 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':test'
14:23:28.665 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :test FAILED
14:23:28.665 [INFO] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] :test (Thread[main,5,main]) completed. Took 5.552 secs.
14:23:28.666 [DEBUG] [org.gradle.execution.taskgraph.AbstractTaskPlanExecutor] Task worker [Thread[main,5,main]] finished, busy: 6.67 secs, idle: 0.021 secs
14:23:28.808 [LIFECYCLE] [org.gradle.BuildResultLogger]
14:23:28.808 [LIFECYCLE] [org.gradle.BuildResultLogger] BUILD FAILED
14:23:28.808 [LIFECYCLE] [org.gradle.BuildResultLogger]
14:23:28.808 [LIFECYCLE] [org.gradle.BuildResultLogger] Total time: 11.75 secs
14:23:28.811 [DEBUG] [org.gradle.api.internal.tasks.compile.daemon.CompilerDaemonManager] Stopping 0 compiler daemon(s).
错误信息:
Unexpected exception thrown.
org.gradle.messaging.remote.internal.MessageIOException: Could not read message from '/127.0.0.1:51041'.
at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:88)
at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionReceive.run(MessageHub.java:230)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: com.esotericsoftware.kryo.KryoException: java.io.IOException: An existing connection was forcibly closed by the remote host
at com.esotericsoftware.kryo.io.Input.fill(Input.java:141)
at com.esotericsoftware.kryo.io.Input.require(Input.java:159)
at com.esotericsoftware.kryo.io.Input.readByte(Input.java:255)
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:64)
at org.gradle.messaging.remote.internal.hub.InterHubMessageSerializer$MessageReader.read(InterHubMessageSerializer.java:53)
at org.gradle.messaging.remote.internal.inet.SocketConnection.receive(SocketConnection.java:83)
... 5 more
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:192)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:379)
at org.gradle.messaging.remote.internal.inet.SocketConnection$SocketInputStream.read(SocketConnection.java:167)
at com.esotericsoftware.kryo.io.Input.fill(Input.java:139)
... 10 more
Unexpected exception thrown.
org.gradle.messaging.remote.internal.MessageIOException: Could not write message [EndOfStream] to '/127.0.0.1:51041'.
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:115)
at org.gradle.messaging.remote.internal.hub.MessageHub$ConnectionDispatch.run(MessageHub.java:279)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: An existing connection was forcibly closed by the remote host
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:51)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:93)
at sun.nio.ch.IOUtil.write(IOUtil.java:51)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:487)
at org.gradle.messaging.remote.internal.inet.SocketConnection$SocketOutputStream.flush(SocketConnection.java:230)
at org.gradle.messaging.remote.internal.inet.SocketConnection.dispatch(SocketConnection.java:113)
... 5 more
FAILED
尝试使用
./gradlew --stop
清理你的守护进程。这对我有用。
这是我的错误。有时我在构建结束时会出现 IDLE 并且永远不会结束。
* What went wrong:
Execution failed for task ':test'.
> A problem occurred starting process 'Gradle Test Executor 1'
您的一项测试很可能会经历
System.exit(1)
。
使用
test -i
在控制台中显示测试结果可能会有所帮助。
检查您的项目是否在内部使用 Java 11 或 Java 1.8 以及您的系统具有的 java:
要检查您的 java 版本,请运行:
javac --version
*请注意,某些 IDE 可能会覆盖该值来构建。
在我的 android 项目中,错误来自于在使用 JUnit5 运行测试时使用 JUnit4 规则。
dependencies {
testImplementation(bConnect.jupiterApi)
testRuntimeOnly(bConnect.jupiterEngine)
}
android {
testOptions {
unitTests.all {
useJUnitPlatform()
}
}
}
class AuthenticationServiceTest {
@get:Rule
val fixedClockRule = FixedClockRule()
迁移到 JUnit5 扩展解决了这个问题
@ExtendWith(JupiterFixedClockRule::class)
internal class AuthenticationServiceTest
我也有类似的问题,但它是由
JAVA_TOOL_OPTIONS
引起的:
JAVA_TOOL_OPTIONS: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/dumps/
不存在的路径
/dumps/
导致了我的问题。