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
create a simple function to request a password:
import javax.swing.JOptionPane
def askPass() {
def msg = 'Enter keystore password'
if (System.console() != null) {
return System.console().readLine(msg)
} else {
return javax.swing.JOptionPane.showInputDialog(msg)
}
}
or if you want Y/n answer:
import javax.swing.JOptionPane
def ask(msg) {
if (System.console() != null) {
return System.console().readLine(msg + ' [y/n]') == 'y'
} else {
def res = JOptionPane.showConfirmDialog(null, msg, "Confirm operation", JOptionPane.YES_NO_OPTION)
return res == JOptionPane.YES_OPTION
}
}
// usage:
task run() {
doFirst {
if (file('out.txt').exists() && !ask('overwrite output?')) {
System.exit(2)
}
}
...
}