System.console() when using the Daemon

While not part of the core gradle plugins, the templates plugin is a handy little thing from Eric Berry. Back in February it was noted that gradle createJavaClass fails with:

Cannot invoke method readLine() on null object

when running using the daemon. At some point the daemon is going to become the default, so what would be the correct way to allow interactive types of gradle sessions using standard in when that change occurs (short of disabling the daemon for those tasks)?

-Spencer

The daemon does handle redirecting stdin (since about milestone 5). I am guessing that this code uses the Java 6 console, which is a different story.

Where is this code so I can check it out?

https://launchpad.net/gradle-templates

TemplatesPlugin.groovy[31]:

static String prompt(String message, String defaultValue = null) {
  if (defaultValue) {
   return System.console().readLine("${inputPrompt} ${message} [${defaultValue}] ") ?: defaultValue
  }
  return System.console().readLine("${inputPrompt} ${message} ") ?: defaultValue
 }

Right, the workaround right now would be to read directly from stdin, which will work.

There wasn’t an existing issue for this, so I’ve raised GRADLE-2310 and linked it to this.

Is this still an issue? ‘Console.readPassword(…)’ is a pretty handy way to get input.

The linked issue (and therefore also this topic) is still unresolved, so the answer is “yes”.

A workaround for this is to use Groovy’s SwingBuilder to pop up a GUI dialog to gather the input.

It would be nice if the suggestion on http://www.gradle.org/docs/current/userguide/signing_plugin.html for gathering the signing info made it clear that it won’t work when using the Gradle daemon. :frowning:

Cant use Grrovys swingbuilder as i run in headless environment