Hello WorldRun the gradle command to build the gradle. This command looks for the build. gradle file in the current directory. We usually call this file a build script. Although it is strictly a build configuration script, as we will see later, this script defines a project and its documentation.
Let's try to create a build Script: Build. gradle
In a shell command line, move to the directory where build. gradle is located and execute the build Script: gradle-Q hello.
Execution of a build script:
There is a shorthand method to define a task, such as Hello above. This shorthand method looks more concise:
A closure execution script named hello is defined above. This task definition style will be used throughout the user guide.
The gradle build script gives you all the power of groovy. As an appealer, first look at this:
Or
As follows:
As you think, you can declare tasks dependent on other tasks.
Insert: run the command line to create the echo.> build. gradle file.
Question: How to output Chinese characters in the command line
Add a dependency. This dependency does not exist (not must be defined before dependency *)
Task taskx's dependency Declaration on task is important for multi-project construction before task definition. Task dependencies will be discussed in more detail in 15.4 adding task dependencies.
Note: you cannot use the shortcut key to point to an undefined task.
Groovy not only defines what a task does, for example, it can also dynamically create a task.
Once a task is created, it can be accessed through APIS. For example, you can dynamically add dependencies for a task at runtime. Ant does not support this.
Alternatively, you can add actions to an existing task.
Note: The Task Name is case-insensitive (when executed ).
Dolast and dofirst can be called and executed multiple times. They add an action at the beginning or end of the task action list, which is executed sequentially in the action list. <Operator is an alias of dolast.
As you noted, there is a convenient symbol in the example to access an existing task. Each task can be viewed as an attribute of the build script.
This makes the code very readable, especially when using the tasks provided by the plug-in, such as compile compilation tasks.
You can add your own attributes to a task. For example, add a property name myproperty, set Ext. myproperty's default value. After the property is complete, it can read and set the value like a predefined task.
Note: ext here should come with gradle. The specified attribute cannot be found after it is removed.
Additional attributes are not limited to tasks. You can read more about them: 13.4.2 "Additional attributes ".
The ant task is the first-class citizen of gradle. It relies on groovy to provide excellent Jicheng for ant tasks. Using gradle is more powerful and convenient than the original build. xml. In the following example, you can learn how to execute ant tasks and access ant attributes.
Note: ant has not been done, skipped
You can perform more operations on the ant build script ,??Use ant from gradle
Later, you will see that these methods can be shared with the construction of sub-projects in the project. If your building logic is complex, gradle provides you with other convenient ways to organize it .? Chapter? 17 ,?Using Ant from gradle