if an `AutoCloseable` `BuildService` is only used ...
# community-support
c
if an
AutoCloseable
BuildService
is only used by an extension is it only closed when the gradle build is over?
v
It is closed somewhere between its last usage and the end of the build. If you for example registered it as operation completion listener or make all tasks
usesService(...)
it, then it will be closed between the last task finished and the end of the build. Otherwise somewhen earlier is quite possible.
c
That's what I'm saying. If there aren't any tasks and it's only exposing stuff through an extension...
Is it simply getting closed at the end of the build?
v
At the very latest or any time earlier
As I said, between the point it is no longer known to be needed and the end of the build
c
Yeah I was just trying to figure out how it would know if it was still needed when it comes to extensions. I'm speculating that this shared service might actually be a bad idea because why am I leaving it open for what's probably the entire length of the build when I could just grab what I need and throw it away
v
I don't know how it is implemented. But my guess would be that as soon as configuration phase is over it is considered unused if it is neither registered as operation completion listener, nor registered as used by any task that is going to run.
m
The exact moment when the service is closed is intentionally underspecified. In the current implementation there are two points: 1. when the build finishes 2. with CC enabled and if the service is not an operation listener - when the configuration phase ends (1) is something that can change in the foreseeable future, so I wouldn't rely on that. If you need the service to survive until the end, you can feed it to a
FlowAction
alongside
FlowProviders.buildWorkResult
. A consequence of (2) is that the service may be created and destroyed twice during the single build, this is just something to be mindful of.
👍 1
c
yeah, I need the opposite, I'm more concerned that it's being held open until the build finishes... I suppose I could stick some logging in and see when...
tbf, I'm not even entirely certain what being "open" means here... it might not even matter