Skip to content

Instantly share code, notes, and snippets.

@jonnycaley
Last active June 18, 2022 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonnycaley/37629cc32f9db78d6d8fbc810c661291 to your computer and use it in GitHub Desktop.
Save jonnycaley/37629cc32f9db78d6d8fbc810c661291 to your computer and use it in GitHub Desktop.
Register BuildDurationService
class BuildTimeLoggerPlugin : Plugin<Project> {
override fun apply(project: Project) {
val gradle = project.gradle
val buildDurationService = registerBuildDurationService(gradle)
}
private fun registerBuildDurationService(gradle: Gradle): Provider<BuildDurationService> {
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java]
val buildDurationService = gradle.sharedServices.registerIfAbsent("build-duration-service", BuildDurationService::class.java) { }
registry.onOperationCompletion(buildDurationService)
return buildDurationService
}
}
fun Gradle.serviceRegistry(): ServiceRegistry = (this as DefaultGradle).services
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment