AMP AMP

How To Install Gradle On Ubuntu 16.04 And Derivatives

To Install Gradle On Ubuntu 16.04 and its Derivatives

Gradle is an open source automation application used for building, testing, publishing, deployment for generating static websites, documentations, etc.. The latest version of Gradle is released with a lot of changes. Not only is Gradle a easy-to-use tool, its installation is also easy.We have already covered the Installation of Gradle on Debian in our previous article, and its installation on Ubuntu is covered in this article.

Prerequisites

Before you start the installation of Gradle, make sure you have Java installed on your Ubuntu machine. You can check your version of Java by running the following command.

user1@linuxhelpubnt:~$ java -version
java version " 1.8.0_121" 
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

Installing Gradle

The Gradle package is available via PPA. So, use the following command to add its repo.

user1@linuxhelpubnt:~$ sudo add-apt-repository ppa:cwchien/gradle
[sudo] password for user1: 
 Gradle is a Groovy based build system.

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.

More info: < http://gradle.org/> 
 More info: https://launchpad.net/~cwchien/+archive/ubuntu/gradle
Press [ENTER] to continue or ctrl-c to cancel adding it

gpg: keyring `/tmp/tmpo66gst52/secring.gpg'  created
gpg: keyring `/tmp/tmpo66gst52/pubring.gpg'  created
gpg: requesting key 9D06AF36 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpo66gst52/trustdb.gpg: trustdb created
gpg: key 9D06AF36: public key " Launchpad PPA for Cheng-Wei Chien"  imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK

Once it is downloaded, use the following command to update the apt sources-list.

user1@linuxhelpubnt:~$ sudo apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu xenial InRelease
Get:2 http://ppa.launchpad.net/cwchien/gradle/ubuntu xenial InRelease [17.5 kB]
Get:3 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease [102 kB]         
Hit:4 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease                       
Get:5 http://ppa.launchpad.net/cwchien/gradle/ubuntu xenial/main amd64 Packages [2,000 B]
Get:6 http://ppa.launchpad.net/cwchien/gradle/ubuntu xenial/main i386 Packages [2,000 B]
Get:7 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease [102 kB]                             
Get:8 http://ppa.launchpad.net/cwchien/gradle/ubuntu xenial/main Translation-en [1,120 B]    
Fetched 227 kB in 1s (116 kB/s)                                     
Reading package lists... Done

After updating the apt sources-list, you can install Gradle by invoking the following command.

user1@linuxhelpubnt:~$ sudo apt-get install gradle
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libpango1.0-0 libpangox-1.0-0
Use ' sudo apt autoremove'  to remove them.
The following additional packages will be installed:
  gradle-3.4 gradle-ppa
The following NEW packages will be installed:
  gradle gradle-3.4 gradle-ppa
0 upgraded, 3 newly installed, 0 to remove and 60 not upgraded.
Need to get 70.3 MB of archives.
After this operation, 79.4 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
.
.
Setting up gradle-ppa (3.4-0ubuntu1) ...
Setting up gradle (3.4-0ubuntu1) ...

Gradle has been installed. If you want to view the information related to Gradle, use the following command.

user1@linuxhelpubnt:~$ gradle --help
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.
--configure-on-demand   Only relevant projects are configured in this build run. This means faster build for large multi-project builds. [incubating]
--console               Specifies which type of console output to generate. Values are ' plain' , ' auto'  (default) or ' rich' .
--continue              Continues task execution after a task failure.
.
.
-v, --version           Print version info.
-x, --exclude-task      Specify a task to be excluded from execution.

You can also check the version of Gradle by running the following command.

user1@linuxhelpubnt:~$ gradle --version

------------------------------------------------------------
Gradle 3.4
------------------------------------------------------------

Build time:   2017-02-20 14:49:26 UTC
Revision:     73f32d68824582945f5ac1810600e8d87794c3d4

Groovy:       2.4.7
Ant:          Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM:          1.8.0_121 (Oracle Corporation 25.121-b13)
OS:           Linux 4.4.0-21-generic amd64

The installation was quite simple, isn' t it? The same method can be used for installing Gradle on all other Ubuntu derivatives such as Ubuntu 15.10, Ubuntu 15.04 Vivid Vervet, Ubuntu 14.10 Utopic Unicorn, Ubuntu 14.04 Trusty Tahr, Ubuntu 12.04 Precise Pangolin, Linux Mint 17.1 Rebecca, Linux Mint 17 Qiana, Linux Mint 13 Maya, Pinguy OS 14.04, Elementary OS 0.3 Freya, Elementary OS 0.2 Luna, Peppermint Five, Deepin 2014, LXLE 14.04, Linux Lite 2, etc.

Tag : Ubuntu Gradle
FAQ
Q
How to modify jvmArguments of runIde task?
A
"runIde task is a Java Exec task and can be modified according to the documentation.

To add some jvm arguments while launching IDE, configure runIde task in the following way:

runIde {
jvmArgs '-DmyProperty=value'
}"
Q
How to modify system properties of runIde task?
A
"Using the very same task documentation, configure runIde task:

runIde {
systemProperty('name', 'value' )
}"
Q
"Is there a way to run a specific Android unit test using Gradle? I've tried

gradle -Dtest.single=UnitTestName connectedInstrumentTest
but it seems to run all the tests in the package. What will do?"
A
"Using test. single appears to be deprecated. The new correct way to do this is

./gradlew ::test --tests "
Q
Why run 'gradle clean'?
A
The clean task is defined by the Java plugin and it simply removes the buildDir folder, thus cleaning everything including leftovers from previous builds which are no longer relevant.
Q
How to Building the Plugin in gradle?
A
"To build the plugin, just type the following command:

./gradlew clean build"