Gradle is the newest addition to the Java build project automation tool family. It is open sourced under Apache License 2.0 and its first version (0.7) was released in 2009. Gradle has been gaining a lot of adoption as it draws on lessons learned from other existing build tools such as Ant and Maven. Several high-profile projects such as Android, Spring Framework, and Hibernate have migrated their build systems to use Gradle.
Gradle Features:
- Declarative Dependency Management
- Declarative Builds
- Build by Convention
- Incremental Builds
- Gradle Wrapper
- Plugins
- Open Source
If you get below error while running the gradle command:
gradle: command not found
you may install the gradle package as shown below as per your choice of distribution.
Distribution | Command |
---|---|
OS X | brew install gradle |
Debian | apt-get install gradle |
Ubuntu | apt-get install gradle |
Alpine | apk add gradle |
Arch Linux | pacman -S gradle |
Kali Linux | apt-get install gradle |
Fedora | dnf install gradle |
Raspbian | apt-get install gradle |
gradle Command Examples
1. Compile a package:
$ gradle build
2. Exclude test task:
$ gradle build -x test
3. Run in offline mode to prevent Gradle from accessing the network during builds:
$ gradle build --offline
4. Clear the build directory:
$ gradle clean
5. Build an Android Package (APK) in release mode:
$ gradle assembleRelease
6. List the main tasks:
$ gradle tasks
7. List all the tasks:
$ gradle tasks --all