Tuesday, 24 October 2017

2. Installing gradle

1. Installing gradle
  1. Before we get and install Gradle, we must make sure we have a Java Development Kit (JDK) installed on our computer.
  2. Gradle requires JDK 5 or higher. Gradle will use the JDK found at the path set on our computer.
  3. Although Gradle uses Groovy, we don't have to install Groovy ourselves,  Gradle bundles the Groovy libraries
  4. We can install in 2 ways
    1. 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.
    2. Install with a package manager : Using various package managers
      1. SDKMAN - is a tool for managing parallel versions of multiple Software Development Kits on most Unix-based systems.
      2. Homebrew - is “the missing package manager for macOS”
      3. Scoop - is a command-line installer for Windows inspired by Homebrew
      4. MacPorts - is a system for managing tools on macOS
  5. Command using package manager
    1. $ sdk install gradle 4.2.1
    2. $ brew update && brew install gradle
    3. $ scoop install gradle
    4. $ sudo port install gradle
  6. Manually install procedure
    1. Download the latest Gradle distribution
    2. Unpack the distribution
    3. Configure your system environment
      1. $ export PATH=$PATH:/opt/gradle/gradle-4.2.1/bin
    4. Verify your installation
      1. gradle -v
2. Run First gradle script
  1. It is time to create our first Gradle build script, Gradle uses the concept of projects to define a related set of tasks.
  2. A Gradle build can have one or more projects.
  3. A project has one or more tasks.
  4. 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.
  5. We use the gradle command to run a build. Gradle will look for a file named build.gradle in the current directory.
  6. 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.'
}
  1. In terminal or cmd and go to the ‘build.gradle’ file path and un the following command
    gradle helloWorld
  2. It will print the Hello world. in terminal console.(It will print task name also)
  3. 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
  1. Above command will give results and any error messages if any.

No comments:

Post a Comment

3. Java Program to create Binary Tree