Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Gradle Essentials

You're reading from   Gradle Essentials Master the fundamentals of Gradle using real-world projects with this quick and easy-to-read guide

Arrow left icon
Product type Paperback
Published in Dec 2015
Publisher
ISBN-13 9781783982363
Length 176 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (2):
Arrow left icon
Abhinandan Maheshwari Abhinandan Maheshwari
Author Profile Icon Abhinandan Maheshwari
Abhinandan Maheshwari
Kunal Dabir Kunal Dabir
Author Profile Icon Kunal Dabir
Kunal Dabir
Arrow right icon
View More author details
Toc

The Gradle command-line interface

Gradle, just like other build tools, is primarily run from a command line. That's why it is worth spending some time to get familiar with its command-line interface. Typically, a gradle command is issued from the root of a project directory with some tasks to be executed. Let's say we are in the hello-gradle directory, which is currently empty.

Gradle provides a very simple command-line interface (CLI), which takes the following form:

gradle [options…] [tasks…]

As we can see, apart from the gradle command itself, everything else is optional. The options tweak the execution of the Gradle whereas tasks, which we will see in detail later, are the basic units of work. Options are common across all projects and are specific to Gradle but tasks may vary depending on the project in which the gradle command is being run.

There are some tasks that are available on all projects. One such task is help:

$ gradle help
:help

Welcome to Gradle 2.9.

To run a build, run gradle <task> ...

To see a list of available tasks, run gradle tasks

To see a list of command-line options, run gradle --help

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 0.639 secs

Gradle is helping us out by telling us how to find all the available tasks and list all command-line options. Let's first check what other tasks are currently available on our project. Remember we are still in the empty directory hello-gradle:

$ gradle tasks
:tasks

------------------------------------------------------------
All tasks runnable from root project
------------------------------------------------------------

Build Setup tasks
-----------------
init - Initializes a new Gradle build. [incubating]
wrapper - Generates Gradle wrapper files. [incubating]

Help tasks
----------
components - Displays the components produced by root project 'hello-gradle'. [incubating]
dependencies - Displays all dependencies declared in root project 'hello-gradle'.
dependencyInsight - Displays the insight into a specific dependency in root project 'hello-gradle'.
help - Displays a help message.
model - Displays the configuration model of root project 'hello-gradle'. [incubating]
projects - Displays the sub-projects of root project 'hello-gradle'.
properties - Displays the properties of root project 'hello-gradle'.
tasks - Displays the tasks runnable from root project 'hello-gradle'.

To see all tasks and more detail, run gradle tasks --all

To see more detail about a task, run gradle help --task <task>

BUILD SUCCESSFUL

Total time: 0.652 secs

This shows us some generic tasks that are available even without us adding any task to our project. We can try running all these tasks and see the output. We will see these tasks in details in the upcoming chapters.

The other useful command gradle help suggested us to check all the available options with the --help option.

Tip

The help task is not the same as the --help option.

When we run the gradle --help command, we get the following output:

$ 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.
…..

(The output is truncated for brevity.)

The option has a long form such as --help and may have a short from such as -h. We have already used one option before, that is --version or -v, which prints information about the Gradle version. The following are some commonly used options; there are many more options, which can be seen using the gradle --help command:

Options

Description

-b, --build-file

This specifies a build file (default: build.gradle)

--continue

This continues task execution even after a task failure

-D, --system-prop

This sets the system property of the JVM

-d, --debug

This prints debug level logs

--gui

This starts Gradle GUI

-i, --info

This prints info level logs

-P, --project-prop

This adds a property to the project

-q, --quiet

This logs only errors

-s, --stacktrace

This prints stack traces for exceptions

-x, --exclude-task

This excludes a specific task

You have been reading a chapter from
Gradle Essentials
Published in: Dec 2015
Publisher:
ISBN-13: 9781783982363
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime