- Mastering Gradle
- Mainak Mitra
- 270字
- 2021-07-16 20:49:33
Our first script
In the last section, we learned how to install Gradle. Now it's time create our very first Gradle script. This script will print Hello Gradle- This is your first script
on the console. Just open a text editor, type in the following three lines, and save the file as build.gradle
.
task helloGradle << { println 'Hello Gradle- This is your first script' }
Then execute the gradle helloGradle
command as follows:
$ gradle helloGradle :helloGradle Hello Gradle- This is your first script BUILD SUCCESSFUL Total time: 4.808 secs
So, what have we done here?
- We have a created a Gradle build script file called
build.gradle
. This is the default name given to a build file. You can give any name to the build file. However, to execute the script, you must use the-b
option with your filename with thegradle
command. Otherwise,the build will fail with theTask '%TASK_NAME%' not found in root project '%PROJECT_NAME'."gradle [-b <file name>] [task1 task2 ….. taskn]
error. - Try the
gradle -b <buildfile_name> helloGradle
command and you should get the same output. - With the gradle command, we have executed a task called
helloGradle
, which prints a line in the console. So, the parameter we passed to the gradle command is the task name. You can execute one to any number of tasks with the Gradle command and these tasks will be executed in the same order as they appear in the command line.Tip
There is a way to define the default task using the
defaultTasks
keyword, which will be executed by default, if user does not mention any specific task to execute on the build file. We'll discuss this more in Chapter 3, Managing Task.
The Gradle command initializes the script, reads all tasks mentioned on the command-line, and executes tasks. Moreover, if any task has multiple dependencies, then dependent tasks are executed in alphabetical order unless those tasks themselves enforce the order. You can find more about task ordering in Chapter 3, Managing Task.
Remember that each Gradle build consists of three components: projects, tasks, and properties. Each build has at least one project and one or more tasks. The name of the project is the parent directory name in which the build file exists.
- Mastering Entity Framework Core 2.0
- 深入淺出Electron:原理、工程與實(shí)踐
- 軟件架構(gòu)設(shè)計(jì):大型網(wǎng)站技術(shù)架構(gòu)與業(yè)務(wù)架構(gòu)融合之道
- MySQL數(shù)據(jù)庫應(yīng)用與管理 第2版
- Java EE框架整合開發(fā)入門到實(shí)戰(zhàn):Spring+Spring MVC+MyBatis(微課版)
- Twilio Best Practices
- Web Development with Django Cookbook
- Java從入門到精通(第4版)
- Python網(wǎng)絡(luò)爬蟲從入門到實(shí)踐(第2版)
- 學(xué)Python也可以這么有趣
- INSTANT Django 1.5 Application Development Starter
- Node.js:來一打 C++ 擴(kuò)展
- MongoDB,Express,Angular,and Node.js Fundamentals
- 速學(xué)Python:程序設(shè)計(jì)從入門到進(jìn)階
- 超簡單:Photoshop+JavaScript+Python智能修圖與圖像自動(dòng)化處理