Skip module build if it hasn't changed in a previous branch

I’m trying to optimize our builds on Jenkins. Gradle easily detects if it needs to compile and rebuild a module by comparing the output of a previous run. However consider on a build server where there are several developers each working in a separate branch. Now typically you start off with a clean slate and rebuild everything from scratch but what if you have:

branchOrJobA\module{A,B,C} branchOrJobB\module{A,B,C}

and developer 1 is working on A, developer 2 is working on B. So both will be compiling C from scratch wasting time.

What I’d like: when either of them finishes, copy the generated .class files somewhere and then in a subsequent run, perhaps via the use of task.onlyIf somewhere I would: a) diff the current module source with a previous source b) If they are different, build as usual (optionally do this at a file-level) c) If they are identical, copy the previous binaries as would happen during compilation and skip the module

Am I going overboard ?

Until Gradle gets a distributed build cache, the most viable option I can think of is to split up the large build into multiple smaller ones that exchange (possibly branch-specific) artifacts via a binary repository (e.g. Artifactory or Nexus). This may allow for branching on a finer-grained level and more artifact reuse.

PS: From my experience, compile time is rarely a bottleneck in Java builds.