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.
signingConfigs {
release {
storeFile file(System.console().readLine("\n\$ Enter keystore path: "))
storePassword System.console().readLine("\n\$ Enter keystore password: ")
keyAlias System.console().readLine("\n\$ Enter key alias: ")
keyPassword System.console().readLine("\n\$ Enter key password: ")
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
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.
If you liked this post, you'll also like...
- Implementing feature toggles for a Spring Boot application - Part 4
- Implementing feature toggles for a Spring Boot application - Part 3
- Implementing feature toggles for a Spring Boot application - Part 2
- Implementing feature toggles for a Spring Boot application - Part 1
- Importing the Yelp dataset into MongoDB
- Clojure Dojo - Levenshtein edit distance
- A simple JMeter test with login
- Implementing Rate Limiting in Rails - Part 2
- Implementing Rate Limiting in Rails - Part 1
- Python Hack - Dynamically override an object's attribute
- Fitting an Image in to a Canvas object
- Accessing Environment Variables in Gradle
- Ruby, Named Capture Groups and Local Variables
- Named Capture Groups in Regular Expressions
- Decomposing URLs in Python
- Shared history in Bash
- Managing Gemsets in Rbenv
- Looking up Compiler params used to compile a Ruby version
- Navigating Stacktraces in Emacs
- Python's bool type
- Graph databases 1 - Modeling
- Validating JSON in Emacs
- My thoughts on Android fragmentation - It is not a bad thing
- Emacs hack: Viewing Git logs while composing commit messages
- Configure Git's comment character
- Oh I can build it in...
- JavaScript, clipboard access and hidden flash widgets
- Reducing Emacs startup time while committing
- My first Firefox plugin: GetCache - View cached version of the current page
- GetCache - A Chrome plugin to view cached version of the current page
- On REST, Content-Type, Google Chrome and Caching
- How Browsers Detect If You Are Offline
- D3.js Workshop
- Visualisation - How European clubs dominate their leagues
- Understanding Python's "with" statement
- Heredocs in Ruby and Python
- Micro Journal - simple Git-backed journal in Python
- VodQA NCR: Maintaining Large Test Suites
- Know Your Tools - Don't Shoot Yourself in the Foot
- Managing security certificates from the console - on Windows, Mac OS X and Linux
- Indian and Pakistani cricketers - who make better debuts?
- Finding un-merged commits with git cherry
- Bullet proof Jenkins setup
- Why your project should have a Getting Started guide.
- Debugging: C Sharp's HttpWebRequest, 100-Continue and nginx
- Wikipedia Page Hopping
- Empathy Log Parser
- Binary Signature Art
- Java Arrays in JRuby
- Autorun.py - Execute stuff on file change