September 23, 2010

Gradle scripts are Groovy scripts. So we can use all the functionality of Groovy in our Gradle scripts. And because we can use Java classes as well, we can simply get user input values from the console using java.io.Console. With the Console class we can for example ask for a value to be used in our script. We can even ask for a password without the password being echoed on the console.

In the following sample build script we have a ask task that uses Console to let the user enter a username and password value. In the print task we use the values that are entered to print them to the console.