Slackbot
10/05/2023, 9:02 PMPedro Lamarão
10/09/2023, 2:49 PMKelvin Chung
10/12/2023, 10:50 PM@ServiceReference. Is there anything special that would need to be accounted for?Kelvin Chung
10/12/2023, 11:32 PMinterface MyExtension {
val service: Property<MyService>
val servers
get() = service.get().servers
}
abstract class MyService: BuildService<BuildServiceParameters.None> {
abstract val servers: NamedDomainObjectContainer<MyInstanceInfo>
fun getClient(name: String): MyClient? { ... }
}
In versions of Gradle with @ServiceReference, MyExtension.service would just be a Provider<MyService> annotated with @ServiceReference? What about versions of Gradle predating @ServiceReference?Pedro Lamarão
10/20/2023, 6:32 PMKelvin Chung
10/20/2023, 6:42 PMTask.usesService() and the like, creating the impression that more hoops were needed. Something like
tasks.withType<MyTask>().configureEach {
client.set(project.the<MyExtension>().getClient("myClient"))
usesService(project.the<MyExtension>().service)
}
The other thing is wrt `MyExtension.servers`; this kind of implies that I am forcibly creating the service during configuration time, which seems off, but I don't know of any suitable workaround if that were the case.Pedro Lamarão
10/20/2023, 7:11 PMservers would return something like service.map { it.servers }Kelvin Chung
10/20/2023, 8:03 PMconfigure<MyExtension> {
servers.register("myClient") { ... }
}
So the link has to be broken somewhere. This is the whole idea behind sharing a NamedDomainObjectProvider between a service and an extension.Pedro Lamarão
10/20/2023, 8:41 PMPedro Lamarão
10/20/2023, 8:42 PMPedro Lamarão
10/20/2023, 8:42 PMNamedDomainObjectProvider in your Plugin.apply method, and explicity "inject" this object into both the extension and the service.