Created
June 18, 2022 13:57
-
-
Save jonnycaley/4ca887e39b373b50353f24db0815cbaf to your computer and use it in GitHub Desktop.
BuildTimeLoggerPlugin - register build task service
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 buildTaskService = registerBuildTaskService(gradle) | |
} | |
private fun registerBuildTaskService(gradle: Gradle): Provider<BuildTaskService> { | |
val registry = gradle.serviceRegistry()[BuildEventListenerRegistryInternal::class.java] | |
val buildTaskService = gradle.sharedServices.registerIfAbsent("build-task-service", BuildTaskService::class.java) { } | |
registry.onTaskCompletion(buildTaskService) | |
return buildTaskService | |
} | |
} | |
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