Hi all. Was hoping for a sanity check on this appr...
# configuration-cache
j
Hi all. Was hoping for a sanity check on this approach because I feel like it may break the configuration cache but I'm not sure. The core of my question is, is it safe to store a lambda in a shared build service (configured in the root build.gradle.kts) that is then used by convention plugins later on? Example in the 🧵
So in my root build.gradle.kts I have:
Copy code
yum {
    loggingConfiguration { 
        dependencies {
            "implementation"(projects.logging)
            "testImplementation"(libs.slf4j.simple)
        }
    }
}
The root convention plugin method looks like:
Copy code
fun loggingConfiguration(action: Project.() -> Unit) {
        YumGlobalConfigService.of(project).get().loggingConfiguration = action
 }
Then each child project's extension calls the following method when I enable logging
Copy code
private fun Project.addLoggingSupport() {
    val service = YumGlobalConfigService.of(this).get() 
    service.loggingConfiguration(this)
}
Important to note that
YumGlobalConfigService.of
is a shared build service
Copy code
fun of(project: Project): Provider<YumGlobalConfigService> {
            return project.gradle
                .sharedServices
                .registerIfAbsent(
                    "YumGlobalConfigService",
                    YumGlobalConfigService::class.java
                ) {
                    /* do no config */
                }
        }