- Gradle Essentials
- Kunal Dabir Abhinandan
- 557字
- 2021-07-30 09:53:51
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:

- Learning Java Functional Programming
- 流量的秘密:Google Analytics網站分析與優化技巧(第2版)
- Spring 5.0 By Example
- Visual FoxPro程序設計教程
- Programming ArcGIS 10.1 with Python Cookbook
- Julia機器學習核心編程:人人可用的高性能科學計算
- Expert Android Programming
- Python機器學習:手把手教你掌握150個精彩案例(微課視頻版)
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- D3.js 4.x Data Visualization(Third Edition)
- 高級語言程序設計(C語言版):基于計算思維能力培養
- Hands-On Full Stack Development with Go
- Java編程的邏輯
- Learning Apache Karaf
- Cocos2d-x Game Development Blueprints