Getting started with Gradle
This tutorial explains about getting started with Gradle, the newest and fast growing build tool. As per the official website, Gradle is explained as,
Gradle is build automation evolved. Gradle can automate the building, testing, publishing, deployment and more of software packages or other types of projects such as generated static websites, generated documentation or indeed anything else.
Gradle combines the power and flexibility of Ant with the dependency management and conventions of Maven into a more effective way to build. Powered by a Groovy DSL and packed with innovation, Gradle provides a declarative way to describe all kinds of builds through sensible defaults. Gradle is quickly becoming the build system of choice for many open source projects, leading edge enterprises and legacy automation challenges.
The official website has detailed documentation hence we shall jump to the installation and basic usage.
1. Installation
Got to link and download the latest version of Gradle zip and extract it to appropriate folder, next
- Create a system property called GRADLE_HOME pointing to the folder of the extracted Gradle zip
- Add GRADLE_HOME/bin to PATH variable.
below is the sample bash profile entry.
1 2 |
export GRADLE_HOME=/Users/msampath/dev/gradle-2.1 export PATH=$GRADLE_HOME/bin:$PATH |
2. Verification
Once the above steps are complete open a new terminal and verify the installation by executing gradle -version on successful installation you should see the below output, if you don’t see the output then repeat the above steps.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
BANL11fe0f3d7:~ msampath$ gradle -version ------------------------------------------------------------ Gradle 2.1 ------------------------------------------------------------ Build time: 2014-09-08 10:40:39 UTC Build number: none Revision: e6cf70745ac11fa943e19294d19a2c527a669a53 Groovy: 2.3.6 Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013 JVM: 1.6.0_65 (Apple Inc. 20.65-b04-462) OS: Mac OS X 10.9.4 x86_64 |
on executing gradle -h displays all the command options.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
BANL11fe0f3d7:1 msampath$ gradle -h USAGE: gradle [option...] [task...] -?, -h, --help Shows this help message. -a, --no-rebuild Do not rebuild project dependencies. -b, --build-file Specifies the build file. -c, --settings-file Specifies the settings file. --cancel Cancels the build in Gradle daemon if it is running. [incubating] --configure-on-demand Only relevant projects are configured in this build run. This means faster build for large multi-project builds. [incubating] --continue Continues task execution after a task failure. -D, --system-prop Set system property of the JVM (e.g. -Dmyprop=myvalue). -d, --debug Log in debug mode (includes normal stacktrace). --daemon Uses the Gradle daemon to run the build. Starts the daemon if not running. --foreground Starts the Gradle daemon in the foreground. [incubating] -g, --gradle-user-home Specifies the gradle user home directory. --gui Launches the Gradle GUI. -I, --init-script Specifies an initialization script. -i, --info Set log level to info. -m, --dry-run Runs the builds with all task actions disabled. --no-color Do not use color in the console output. --no-daemon Do not use the Gradle daemon to run the build. --offline The build should operate without accessing network resources. -P, --project-prop Set project property for the build script (e.g. -Pmyprop=myvalue). -p, --project-dir Specifies the start directory for Gradle. Defaults to current directory. --parallel Build projects in parallel. Gradle will attempt to determine the optimal number of executor threads to use. [incubating] --parallel-threads Build projects in parallel, using the specified number of executor threads. [incubating] --profile Profiles build execution time and generates a report in the <build_dir>/reports/profile directory. --project-cache-dir Specifies the project-specific cache directory. Defaults to .gradle in the root project directory. -q, --quiet Log errors only. --recompile-scripts Force build script recompiling. --refresh-dependencies Refresh the state of dependencies. --rerun-tasks Ignore previously cached task results. -S, --full-stacktrace Print out the full (very verbose) stacktrace for all exceptions. -s, --stacktrace Print out the stacktrace for all exceptions. --stop Stops the Gradle daemon if it is running. -u, --no-search-upward Don't search in parent folders for a settings.gradle file. -v, --version Print version info. -x, --exclude-task Specify a task to be excluded from execution. BANL11fe0f3d7:1 msampath$ |
I hope this has been useful for you and I’d like to thank you for reading. If you like this article, please leave a helpful comment and share it with your friends.