concept lifecycle event in category gradle

This is an excerpt from Manning's book Gradle in Action - corrected 9052019.
As a build script developer, you’re not limited to writing task actions or configuration logic, which are evaluated during a distinct build phase. Sometimes you’ll want to execute code when a specific lifecycle event occurs. A lifecycle event can occur before, during, or after a specific build phase. An example of a lifecycle event that happens after the execution phase would be the completion of a build.
Suppose you want to get feedback about failed builds as early as possible in the development cycle. A typical reaction to a failed build could be that you send an email to all developers on the team to restore the sanity of your code. There are two ways to write a callback to build lifecycle events: within a closure, or with an implementation of a listener interface provided by the Gradle API. Gradle doesn’t steer you toward one of the options to listen to lifecycle events. The choice is up to you. The big advantage you have with a listener implementation is that you’re dealing with a class that’s fully testable by writing unit tests. To give you an idea of some of the useful lifecycle hooks, see figure 4.11.
Gradle integrates with a wide range of Java and Groovy unit testing frameworks. By the end of this chapter, you’ll write tests with JUnit, TestNG, and Spock, and execute them as part of the build lifecycle. You’ll also tweak the default test execution behavior. You’ll learn how easy it is to control the test logging output and to add a hook or listener to react to test lifecycle events. We’ll also explore how to improve the performance of big test suites through forked test processes. Integration and functional tests require a more complex tooling setup. You’ll learn how to use the third-party tools H2 and Geb to bootstrap your test code.