Unfortunately, the build cache is disabled by default. But as an author of a Gradle plugin with cacheable tasks I’d like to make it as easy as possible for the user’s of the plugin to benefit from task caching across different projects that use the plugin.
So, is there a way to programmatically enable the build cache, or maybe even enable the build cache only for my plugin’s task? This would avoid each user of the plugin to individually enable the build cache.
Thanks @miker256, but that doesn’t help. I’ve already opted-in for the build cache via the @Cacheable annotation for my tasks, but the users of my plugin would still need to set org.gradle.caching=true on their side in the project that applies the plugin to actually benefit from the caching. And that’s exactly what I want to avoid, I want my tasks to benefit from the global build cache even if the user “forgets” to set org.gradle.caching=true.
This just doesn’t seem like a good idea. Users should understand caching and apply it when they want. Plugin authors shouldn’t be forcibly overriding that. If a particular organisation wants to enforce it, they can use a custom Gradle distribution, or system-wide environment variables, or something like that.
Maybe just output a warning of caching is not enabled, with a message explaining how to enable it?