Console.readline() does not print text if run from doLast with gradle 2.13

I have a script that ask for user input using System.console().readline(‘label’). The label is printed on console and the user can type something.
I upgraded from gradle 2.12 to 2.13 and now the first label I use in the task disappears.

For example, when I run the following:

def console = System.console()
def firstname
def lastname

task run {
    doLast {
        firstname = console.readLine('> What is your first name?: ')
        lastname = console.readLine('> What is your last name?: ')
    }
}

I get that with 2.12:

"gradle-2.12/bin/gradle" run
> Building 0% > :run> What is your first name?: John
> What is your last name?: Doe
:run

And that with 2.13:

> "gradle-2.13/bin/gradle" run
> Building 0%> What is your > Building 0% > :runJohn
> What is your last name?: Doe
:run

The first label (> What is your first name?) is not showing.

However, if I change the script with:

def console = System.console()
def firstname
def lastname

task run {
    firstname = console.readLine('> What is your first name?: ')
    lastname = console.readLine('> What is your last name?: ')
}

(removing the doLast) I get the correct output with both versions.

Thanks, I raised GRADLE-3446. I suspect this is behaving differently because we changed the way we print messages to the screen that causes the “status line” to overwrite the prompt you’re providing.

In general, reading System.in and System.console doesn’t work very well from within a Gradle script. It also requires users to run a build without the daemon enabled and it’s hard for users to provide input from the IDE. This is something that’s on our radar, but we haven’t planned for when we’ll address this.

If a user can provide input either via gradle.properties, command-line properties or the like, that’s better. I’d only try to use System.in/System.console when you need something sensitive.

I’m having the same issue, and the use case is exactly for “sensitive” information. Writing passwords into gradle.properties (or passing on the command line, which then goes into bash history), is just not an option.