Using `BuildListener` in Gradle Configuration Cache compatible plugin

I write a plugin that has to measure the duration of build configuration. I want to make it Gradle Configuration Cache compatible as well.

I see that this 3rd party plugin, gradle-analytics-plugin does exactly what I’m looking for, but uses InternalBuildService for that: see BuildInitializationService. At the same time, I can see in the Gradle documentation that if plugins intend to be compatible with configuration cache, they “must not register any build listeners”.

My question: is it idiomatic to use InternalBuildService in the case I describe, or, if it’s not, could you share an alternative for that? Are there any threats to use InternalBuildService in a way that gradle-analytics-plugin uses it?

It is an internal class (and also some other internal classes are used), so no, this is of course not idiomatic and may break with any minor release. :smiley:

And yes, registering any build listener is CC incompatible.

There is no alternative I’m aware that you could use, besides creating a build scan and looking at that.

I see, thank you for the prompt response! :slight_smile:

1 Like