Infrastructure worth keeping — and kept patched.

Can feature branches share the build cache with main?

Your feature-branch builds do reuse what main already built. Give them the read-only login and turn pushing off, so a branch reads main's results without adding its own.

The short answer

What to do

Our advice, not a test result:

To see why a laptop restores what CI built, see your laptop builds reuse what CI already built.

How we checked

We made a real git repository with a four-module project on main and three branches. feature-a changes the body of a method in core. feature-a2 makes the same change on another branch. feature-b adds a public method to core. We ran the builds below in order against one new server with a read-write login and a read-only login.

BuildLogin, pushingcoreutilapiappEntries before and after
mainwrite, onranranranran0 to 13
feature-aread-only, onranranranran13 to 13
feature-bread-only, onranranranran13 to 13
feature-aread-only, offranfrom cachefrom cachefrom cache13 to 13
feature-awrite, onranfrom cachefrom cachefrom cache13 to 14
main afterwardsread-only, offfrom cachefrom cachefrom cachefrom cache14 to 14
feature-bwrite, onranranranran14 to 18
main afterwardsread-only, offfrom cachefrom cachefrom cachefrom cache18 to 18
feature-a2read-only, offfrom cachefrom cachefrom cachefrom cache18 to 18
main after merging feature-a (a fast-forward)write, onfrom cachefrom cachefrom cachefrom cache18 to 18

Each cell is the compile task of that module. Each build used a clean checkout of the branch, a new empty Gradle home, no Gradle daemon and no local build cache. The first build stored 13 entries: four compile outputs and nine other entries, the compiled build scripts. After the read-only builds with pushing on, the entry names on the server were the same as before. After the write builds, every entry that main had stored was still there. The two refused-upload builds each printed one line saying the entry could not be stored, with response status 403, and ended with a line saying the remote cache was disabled during the build due to errors.

Setup: FosterStack Cache 0.2.1, Gradle 9.8.0, Temurin 21.0.12.1, a Mac (arm64), over plain HTTP on the same machine, with test passwords. The project is the four-module project from Gradle build cache for a monorepo. We make no claim about build times.

Not tested: Maven, tasks other than compile, a branch that changes a build script or a dependency, a branch from a fork, pull requests as such, branches with more than one commit, a merge that is not a fast-forward (ours was a fast-forward), other Gradle versions, TLS, and many branches building at once.