1. Installing gradle
- Before we get and install Gradle, we must make sure we have a Java Development Kit (JDK) installed on our computer.
- Gradle requires JDK 5 or higher. Gradle will use the JDK found at the path set on our computer.
- Although Gradle uses Groovy, we don't have to install Groovy ourselves, Gradle bundles the Groovy libraries
- We can install in 2 ways
- Install manually : Gradle is available on the Gradle website, at http://www.gradle.org/downloads. From this page we can download the latest release of Gradle.
- Install with a package manager : Using various package managers
- SDKMAN - is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.
- Homebrew - is “the missing package manager for macOS”
- Scoop - is a command-line installer for Windows inspired by Homebrew
- MacPorts - is a system for managing tools on macOS
- Command using package manager
- $ sdk install gradle 4.2.1
- $ brew update && brew install gradle
- $ scoop install gradle
- $ sudo port install gradle
- Manually install procedure
- Download the latest Gradle distribution
- Unpack the distribution
- Configure your system environment
- $ export PATH=$PATH:/opt/gradle/gradle-4.2.1/bin
- Verify your installation
- gradle -v
2. Run First gradle script
- It is time to create our first Gradle build script, Gradle uses the concept of projects to define a related set of tasks.
- A Gradle build can have one or more projects.
- A project has one or more tasks.
- Tasks are a unit of work that need to be executed by the build, examples of tasks are compiling source code, packaging class files into a JAR file, running tests, or deploying the application.
- We use the gradle command to run a build. Gradle will look for a file named build.gradle in the current directory.
- No need to create a project, just create a file with name ‘build.gradle’ and write the below code in that file.
task helloWorld << {
println 'Hello world.'
}
|
- In terminal or cmd and go to the ‘build.gradle’ file path and un the following command
gradle helloWorld - It will print the Hello world. in terminal console.(It will print task name also)
- Along with result we will get so many message, if we want to suppress the unwanted messages we need to use below command.
gradle --quiet helloWorld
gradle --q helloWorld
gradle --q helloWorld
- Above command will give results and any error messages if any.