This message was deleted.
# plugin-development
s
This message was deleted.
t
You can register a build service and then listen on a few events: https://docs.gradle.org/current/userguide/build_services.html#operation_listener (there's also
BuildListener
but it's not compatible with configuration cache, so not future-proof: https://docs.gradle.org/current/userguide/configuration_cache.html#config_cache:requirements:build_listeners)
b
Are services shared accross all projects or specific per-project in a milti-module build?
i.e. do i need to be careful to only register it on rootProject if I want only a single instance of it accross all projects?
v
You register the operation completion listener on
BuildEventsListenerRegistry
which should be a build-wide registry as far as I remember. Once you add an operation completion listener to it, you should be fine. Something like
Copy code
abstract class TaskFailureHandler : BuildService<BuildServiceParameters.None>, OperationCompletionListener {
    override fun onFinish(event: FinishEvent?) {
        val result = (event as? TaskFinishEvent)?.result as? TaskFailureResult ?: return
        result.failures.forEach { 
            println(it)
        }
    }
}
JavaDoc of
BuildEventsListenerRegistry
also says
Allows a plugin to receive information about the operations that run within a build.
b
Thanks both. This works like a charm!
👌 1