I\'m trying to get my gradle builds to prompt at the console for a password using examples from stack overflow
When I have a statment such as:
def pa
Executing System.getConsole()
from Gradle when org.gradle.daemon
property is true
, or when it's executed from an IDE like IntelliJ or Android Studio it returns null
. So for example do System.console().readLine()
becomes not possible.
Furthermore starting from Gradle 3.0 gradle.daemon is turned on by default.
Then instead of a workaround to use System.getConsole()
I purpose an alternative, use ant.input
like so:
task avoidNullOnConsole << {
ant.input(message: 'Enter keystore password:', addproperty: 'userInputPassword', defaultValue : '1234')
def password = ant.properties.userInputPassword
}
In this case ant.input
shows the message
and adds the user input in ant.properties
using as a property name the value defined in addProperty
. If there is no user input then the value defined in default
attribute is used.
Once executed you can get the user input using ant.properties.yourProperty
or ant.properties['yourProperty']
.
You can check the rest of the ant.input attributes here.
Note: If you want to use ant.input
multiple times take in account that you cannot override and existing property so addProperty
attribute must be different for each one.