Java Gradle 构建失败:进程“Gradle Test Executor 1”以非零退出值 1 完成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23523831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 23:34:40  来源:igfitidea点击:

Gradle build fail: Process 'Gradle Test Executor 1' finished with non-zero exit value 1

javagradle

提问by user3195786

Gradle build fails when it gets to the :testtask (junit tests). It gives the error

Gradle 构建在到达:test任务(junit 测试)时失败。它给出了错误

Process 'Gradle Test Executor 1' finished with non-zero exit value 1

I am using gradle with a java project in eclipse. Gradle 1.12 and Java 7. The problem seems to be happening when a test is run on a class that connects to a database. The odd thing is that the program and tests work fine as java applications. There are no problems with the database connection and it compiles and runs correctly. Does gradle do something that could mess with how it connects to external database servers? The problem could have nothing to do with the database so any solution is appreciated. I've looked online and on the official gradle site but nothing was helpful. Thanks.

我在 eclipse 中的 java 项目中使用 gradle。Gradle 1.12 和 Java 7。当在连接到数据库的类上运行测试时,问题似乎发生了。奇怪的是,程序和测试作为 Java 应用程序运行良好。数据库连接没有问题,它可以正确编译和运行。gradle 是否做了一些可能会影响它如何连接到外部数据库服务器的事情?该问题可能与数据库无关,因此任何解决方案都值得赞赏。我在网上和官方 gradle 网站上查看过,但没有任何帮助。谢谢。

EDIT

编辑

Debug results:

调试结果:

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).

Error Message:

错误信息:

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.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.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

回答by user1707414

Most probably one of your test go through a System.exit(1) It may help to display test result in console using test -i

很可能您的测试之一通过 System.exit(1) 使用 test -i 在控制台中显示测试结果可能会有所帮助

回答by Ali

Try cleaning your daemons with ./gradlew --stop. It works for me. This was my error. also sometimes I got an IDLE at the end of the build and never ends.

尝试使用./gradlew --stop. 这个对我有用。这是我的错误。有时我会在构建结束时得到一个空闲并且永远不会结束。

* What went wrong:
Execution failed for task ':test'.
> A problem occurred starting process 'Gradle Test Executor 1'