Last active
June 18, 2022 14:00
-
-
Save jonnycaley/37629cc32f9db78d6d8fbc810c661291 to your computer and use it in GitHub Desktop.
Register BuildDurationService
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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