Can't read from System.console in cygwin

I’m using System.console.readPassword in a gradle to get credentials for the uploadArchives task, which we obviously don’t want to store in a file on disk. This works perfectly in OSX, Windows, and Linux environments, but does not work under Cygwin. I get “Cannot invoke method readLine() on null object”. I think the issue is that System.console returns null under Cygwin. I’m using Gradle version 1.0, and I am not using the daemon.

Thanks,

Steve

This is not a Gradle deficiency.

The ‘System.console()’ method is free to return ‘null’ if a console object for the environment can’t be provided, which it can’t be for Cygwin.

If you try to run a plain Java program that uses ‘System.console()’ on Windows it will exhibit the same behaviour.

You can find a rather long discussion about why this doesn’t work here.

That’s too bad. I remember hearing at UberConf that Gradle behavior in Cygwin was going to be improved, and I was hoping this would be part of it.

Thank you for looking into it,

Steve

We do intend to solve the use case of prompting for credentials, however. We will add an API/DSL to allow you to receive input from the user, plus a bunch of implementations for this. One such implementation will be backed by System.console when available, with a fallback to some native stuff when running under java 5 or cygwin. This will also work when using the daemon/tooling API.