This message was deleted.
# configuration-cache
s
This message was deleted.
c
Possibly through events received on build service.
d
could you elaborate about this or some doc so i can learn more? Thanks
c
https://docs.gradle.org/current/userguide/build_services.html - see if OperationCompletionListener meets your needs.
v
It does not have to be a build service unless you also need to do something at the end of the build, does it? A plain implementation of the listener should suffice iirc.
c
Iirc build service is the only configuration cache compatible way of having a listener.
v
I quickly tested with
Copy code
abstract class Listener : OperationCompletionListener {
    override fun onFinish(event: FinishEvent?) {
        println("event: $event")
    }
}
interface RegistryProvider {
    @get:Inject
    val registry: BuildEventsListenerRegistry
}
objects.newInstance<RegistryProvider>().registry.onTaskCompletion(provider { objects.newInstance<Listener>() })
and
Copy code
class Listener : OperationCompletionListener {
    override fun onFinish(event: FinishEvent?) {
        println("event: $event")
    }
}
interface RegistryProvider {
    @get:Inject
    val registry: BuildEventsListenerRegistry
}
objects.newInstance<RegistryProvider>().registry.onTaskCompletion(provider { Listener() })
and both work perfectly fine with CC.
c
Plugins and build scripts must not register any build listeners. That is listeners registered at configuration time that get notified at execution time. For example a
BuildListener
or a
TaskExecutionListener
.
These should be replaced by build services, registered to receive information about task execution if needed.
v
Well, as I said, I tried and it works. ๐Ÿ™‚ Maybe the docs are misleading and a
OperationCompletionListener
is ok? Besides that, the listener is not registered ad configuration time, that's why it is provided through a
Provider
which I guess is what makes it ok. Gradle will then probably call the provider at an appropriate time and all is well.
c
v
From a quick look I'd say this still matches what I said.
c
agreed.
looks like if you use the newer listeners / Providers all is good; the legacy stuff is bad.
๐Ÿ‘Œ 1
e
Hi @Vampire , before/AfterTask has a solution, but looks like
Copy code
gradle.buildFinished {
does not have a replacement api?
v
It has, just a bit more footwork. Create a build service, make it
AutoCloseable
, register it as
OperationCompletionListener
. Then the
close
method will be called somewhen between the last task has finished and the build is finished.
๐Ÿ™ 1
party gradlephant 1
e
Ohhhhh thatโ€™s awesome!
@Vampire btw, I saw a lot of events are ready in Gradle(not internal), will they be added to BuildEventsListenerRegistry in the future? Now it has
Copy code
buildEventsListenerRegistry.onTaskCompletion
only.
v
I have no idea
๐Ÿ‘ 1
d
thanks for reply, i just tried it and it works. I also tried to call
project.buildScan.tag = "result"
to tag result from Listener class, but it cannot read property project inside there. Any idea how do we get result from Listener or pass some other listener to call
project.buildScan.tag = "result"
? because i need to add result from listener (task executed info) on buildscan.
I think i already find solution for this, thanks