Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

723
Vistas
Gradle console() is null with daemon disabled

I'm using Gradle 2.13 with Java 1.8.0_121.

One of our Gradle tasks relies on user input.

def user = System.console().readLine('Please enter new user username: ')

However I get the following error: > Cannot invoke method readLine() on null object

So console() must be null... okay. I found this related issue suggesting to disable the daemon.

I did that and ran it with ./gradlew configureTask --no-daemon but got the same result... same error. I'm pretty sure it's not using the daemon as I get the following message: To honour the JVM settings for this build a new JVM will be forked. Please consider using the daemon: https://docs.gradle.org/2.13/userguide/gradle_daemon.html.

So if the Gradle daemon is not causing this issue, what else could be? Does anyone more experienced with Gradle know?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Gradle says it needs to run the build in a subprocess because of something in your build settings:

To honour the JVM settings for this build a new JVM will be forked.

And I guess Gradle creates that subprocess in a way that allows it to grab the output (which is the default with the APIs Java offers to spawn subprocesses). As a result, the subprocess does not have access to I/O of your terminal, and System.console() is null within that process: it is not attached to the system console.

It got me curious so I came up with a script that demonstrates the issue (using Groovy for its conciseness, it's the same thing as Java here):

import java.io.Console

println "Console for main JVM: " + System.console()

Process p1 = new ProcessBuilder("groovy", "-e", "print System.console()")
    .redirectErrorStream(true)
    .start()
p1.waitFor()
println "Console for child JVM: " + p1.text

Process p2 = new ProcessBuilder("groovy", "-e", "println 'Console for child JVM with inherited IO: ' + System.console()")
    .redirectErrorStream(true)
    .inheritIO() // <- this changes everything, as now p2 is attached to system console
    .start()
p2.waitFor()
// No need to (actually cannot) get output of p2, as I/O is inherited by p2 it gets printed to terminal directly

Result:

Console for main JVM: java.io.Console@64cd705f
Console for child JVM: null
Console for child JVM with inherited IO: java.io.Console@3c130745

So Gradle is probably building the subprocess like p1 in my example. And I guess it needs to, because it needs to inspect the output (and not let it go directly to system output).

I think your only solutions are:

  • find a way to get Gradle do the build in the main JVM, without forking. Not a Gradle expert so I don't know how but the message seems to imply it's possible.
  • find another way to get user input. Maybe a Swing dialog? (not very elegant but hey, a build that takes user input is not very elegant in the first place, so the way it is collected does not matter much at this point)
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda