There is no event for that (yet). If it is one of your block you are interested in, there are Block methods. If you want that check with a custom item, onBlockDestroyed in Item would work too. For all other cases, a coremod or TickHandler. Have a look here for my use case of a.
- Gradle Tutorial
- Gradle Useful Resources
- Selected Reading
Gradle provides a command line to execute build script. It can execute more than one task at a time. This chapter explains how to execute multiple tasks using different options.
Executing Multiple Tasks
You can execute multiple tasks from a single build file. Gradle can handle that build file using gradle command. This command will compile each task in the order that they are listed and execute each task along with the dependencies using different options.
Example − There are four tasks - task1, task2, task3, and task4. Task3 and task4 depends on task 1and task2. Take a look at the following diagram.
In the above 4 tasks are dependent on each other represented with an arrow symbol. Take a look into the following code. Copy can paste it into build.gradle file.
You can use the following code for compiling and executing above task.
Output:
Excluding Tasks
While excluding a task from the execution you can use –x option along with the gradle command and mention the name of the task, which you want to exclude.
Use the following command to exclude task4 from the above script.
Output:
Continuing the Build When a Failure Occurs
Gradle will abort execution and fail the build as soon as any task fails. You can continue the execution even when a failure occurs. For this you have to use –continue option with the gradle command. It handles each task separately along with their dependences. And the main important point is it will catch each encountered failure and report at the end of the execution of the build. Suppose if a task fails then the dependent subsequent tasks also will not be executed.
Selecting Which Build to Execute
When you run the gradle command, it looks for a build file in the current directory. You can use the –b option to select a particular build file along with absolute path. The following example selecting a project hello from myproject.gradle file which is located in the subdir/ take a look into it.
You can use the following command to execute the above script.
Output:
Obtaining Build Information
Gradle provides several built-in tasks for retrieving the information details regarding the task and the project. This can be useful to understand the structure and the dependencies of your build and for debugging problems. You can use project report plugin to add tasks to your project, which will generate these reports.
Listing Projects
You can list the project hierarchy of the selected project and their sub projects using gradle –q projects command. Here is the example, use the following command to list all the project in the build file.
Output:
The report shows the description of each project if specified. You can use the following command to specify the description. Paste it in the build.gradle file.
Listing Tasks
You can list all the tasks which belong to the multiple projects by using the following command.
Output:
You can use the following command to display the information of all tasks.
Output:
Here are some list of commands in a table description different options.
Sr. No. | Command | Description |
---|---|---|
1 | gradle –q help –task <task name> | Provides the usage information (such as path, type, description, group) about a specific task or multiple tasks. |
2 | gradle –q dependencies | Provides a list of dependencies of the selected project. |
3 | gradle -q api:dependencies --configuration <task name> | Provides the list of limited dependencies respective to configuration. |
4 | gradle –q buildEnvironment | Provides the list of build script dependencies. |
5 | gradle –q dependencyInsight | Provides an insight into a particular dependency. |
6 | Gradle –q properties | Provides the list of properties of the selected project. |