Gradle without $TERM

I’m trying to run Gradle in a tox session and see some interesting errors:

tox -vr

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
F
some.py Executing: script/gradlew -i --stacktrace tasks
Initialized native services in: /home/akovi/.gradle/native

FAILURE: Build failed with an exception.

* What went wrong:
Could not open terminal for stdout: $TERM not set

This is easily reproducible by unsetting TERM and running any gradle commands. In server sessions it is common that TERM is not set, so I think this is a bug.

Before I upgraded to 3.0, I was able to produce a stack trace with 2.7 (it seems to be not possible any more with 3.0)

FAILURE: Build failed with an exception.

* What went wrong:
Could not open terminal for stdout: $TERM not set

* Try:
Run with --debug option to get more log output.

* Exception is:
net.rubygrapefruit.platform.NativeException: Could not open terminal for stdout: $TERM not set
	at net.rubygrapefruit.platform.internal.TerminfoTerminal.init(TerminfoTerminal.java:49)
	at net.rubygrapefruit.platform.internal.WrapperTerminal.init(WrapperTerminal.java:41)
	at net.rubygrapefruit.platform.internal.AbstractTerminals.getTerminal(AbstractTerminals.java:35)
	at org.gradle.internal.nativeintegration.console.NativePlatformConsoleDetector.getConsole(NativePlatformConsoleDetector.java:42)
	at org.gradle.logging.internal.ConsoleConfigureAction.execute(ConsoleConfigureAction.java:38)
	at org.gradle.logging.internal.ConsoleConfigureAction.execute(ConsoleConfigureAction.java:29)
	at org.gradle.logging.internal.OutputEventRenderer.attachProcessConsole(OutputEventRenderer.java:77)
	at org.gradle.logging.internal.DefaultLoggingManager.attachProcessConsole(DefaultLoggingManager.java:165)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:204)
	at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
	at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
	at org.gradle.launcher.Main.doAction(Main.java:33)
	at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
	at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
	at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
	at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
	at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)

Another interesting issue is when I run tox with nohup, the build succeeds; however, exceptions are present in the log:

nohup tox -vr

some.py Starting a Gradle Daemon (subsequent builds will be faster)
Exception in thread "DisconnectableInputStream source reader" org.gradle.api.UncheckedIOException: java.io.IOException: Bad file descriptor
        at org.gradle.internal.UncheckedException.throwAsUncheckedException(UncheckedException.java:43)
        at org.gradle.util.DisconnectableInputStream$1.run(DisconnectableInputStream.java:125)
        at java.lang.Thread.run(Thread.java:745)
Caused by: java.io.IOException: Bad file descriptor
        at java.io.FileInputStream.readBytes(Native Method)
        at java.io.FileInputStream.read(FileInputStream.java:272)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:334)
        at org.gradle.util.DisconnectableInputStream$1.run(DisconnectableInputStream.java:96)
        ... 1 more
:clean UP-TO-DATE
:sometask

BUILD SUCCESSFUL

Gradle details:
------------------------------------------------------------
Gradle 3.0
------------------------------------------------------------

Build time:   2016-08-15 13:15:01 UTC
Revision:     ad76ba00f59ecb287bd3c037bd25fc3df13ca558

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.7.0_111 (Oracle Corporation 24.111-b01)
OS:           Linux 3.19.0-32-generic amd64

Hi Kövi,

Thanks for reporting the problem. This problem has a Jira issue, it’s https://issues.gradle.org/browse/GRADLE-2634 .
Pull requests are welcome! :slight_smile:

Regards,

Lari

1 Like

I now noticed that you also reported another problem about nohup tox -vr failing. Thanks for reporting that as well. I was able to reproduce it with nohup ./gradlew help.
I created https://issues.gradle.org/browse/GRADLE-3535 for that.

1 Like

Hi,

I just fixed https://issues.gradle.org/browse/GRADLE-2634. This will be included in Gradle 3.1.

Regards,
Stefan

1 Like