- 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:

- Implementing Modern DevOps
- 零基礎學C++程序設計
- Java 9 Concurrency Cookbook(Second Edition)
- 青少年軟件編程基礎與實戰(圖形化編程三級)
- Flash CS6中文版應用教程(第三版)
- 機械工程師Python編程:入門、實戰與進階
- TypeScript項目開發實戰
- 深入RabbitMQ
- 軟件測試實用教程
- 新一代SDN:VMware NSX 網絡原理與實踐
- 基于SpringBoot實現:Java分布式中間件開發入門與實戰
- Python Essentials
- uni-app跨平臺開發與應用從入門到實踐
- Java Web應用開發項目教程
- OpenCV 3計算機視覺:Python語言實現(原書第2版)