Reading user input in Gradle scripts

Continuing from the last blog post, I have been looking at reading user input from a Gradle script. This was a result of Stack Overflow user user672009’s question about prompting for input from a Gradle script so the one does not have to include passwords in the script while checking in.

Just like the last example, the fact that Gradle scripts are written in a Groovy DSL comes to our help. Groovy’s System. console(). readLine can be called from inside Gradle tasks. The same recipe from the last post can be rewritten to prompt for various parameters.

This is a bad idea

While Gradle allows this kind of prompts, this is a bad pattern for a build script, especially when the script is run remotely, for example on a Continuous Integration 1 environment. The correct way to prevent hard coding of parameters like this is to access them from environment variables.

Continuous Integration (CI) is a software development practice where code from different developers, on different components are integrated frequently with the aid of an automated build. Martin Fowler has a great article about it.
[return]

If you have questions or comments about this blog post, you can get in touch with me on Twitter @sdqali.