Build Cache Publication from CI -- Without Using Cache


I followed the instructions regarding setting-up the build cache. I have added the prescribed entries to my settings.gradle:

ext.isCiServer = System.getenv().containsKey("CI")

buildCache {
    local {
        enabled = !isCiServer
    remote(HttpBuildCache) {
        url = ''
        push = isCiServer

During my CI builds I can verify that isCiServer is resolving the correct value, as I see:

Using HTTP build cache ( as remote build cache, push is enabled.

However, when some of my tasks run, I’m seeing that they’re using the cache:

:MyProject:MySubproject:compileJava FROM-CACHE

As advised on the build cache user manual page, I don’t want to have my CI build retrieve artifacts from the cache. It seems strange that the example from that page would support that.

How can I disable the retrieval of cached task output during a CI build?

(Stefan Wolf) #2


it is perfectly fine that CI builds retrieve artifacts from the build cache. Retrieving artifacts from the build cache should always be good, just when pushing artifacts to the build cache one needs to be sure that the artifacts are fine. This is why we suggest that only CI builds running clean push to the build cache and discourage developers publishing artifacts to the build cache.



Thanks for your thoughts Stefan, when I read the build cache documentation I had a different interpretation:

The recommended use case for the build cache is that your continuous integration server populates the remote build cache with clean builds while developers pull from the remote build cache and push to a local build cache.

I had assumed that a clean build would not contain any output from tasks that had been cached from a previous run.

This makes me slightly nervous. If a plugin that I have included in my project has a bug in its UP-TO-DATE checking I could end up with a CI build that continues to pass, despite the fact that --no-build-cache would fail.

In my opinion, that’s a major issue.

(Stefan Wolf) #4

A bug in UP-TO-DATE checking is not enough to have a passing CI build which should actually fail. It needs to be a bug in UP-TO-DATE checking for a cacheable task. Currently, only some tasks that ship with Gradle are cacheable and we put some extra effort to make these safe.
If you really want to be on the super safe side you can still run your build with --rerun-tasks. This will stop loading task outputs from the build cache.


Thanks for the hint about --rerun-tasks, I’ll use that to get the desired behaviour.

I’m not so worried about core gradle plugins having bugs in UP-TO-DATE, I’m more concerned about third-party plugins. I’m sure there are a number of plugins that will be looking to adopt the build caching mechanism.

Thanks for your help.