How does setup-java's new JDK cache work?

November 16, 2026 5 answers
Asked by m.841+valvepencil

I heard setup-java can cache JDK downloads now. How is that different from its existing dependency cache, and when would it actually speed up a workflow?

Answers

9j!canvasgrommet_416

The upcoming v6 release adds a separate cache for JDK installations. If setup-java installs a JDK that wasn't already in the runner tool cache, it can save that installation and restore it on later runs instead of downloading and extracting it again.

Setting cache to maven, gradle, or sbt also opts into the JDK cache. You can instead use cache-jdk: true if you only want the JDK cache. It is separate from dependency and wrapper caches, so a dependency change doesn't need to invalidate the JDK entry.

_v83~chalkwicket.2:

That distinction matters if the runner image already includes the requested JDK. In that case, setup-java can use the tool cache rather than downloading it in the first place.

Reply to this answer
Ravlek+9w

There is a tradeoff, not a free speed boost. In one five-run test on ubuntu-latest with Microsoft Build of OpenJDK 17.0.19, the median warm setup step dropped from 7 seconds to 3, and the median job from 24 seconds to 18. The cached JDK used about 175 MiB.

Results will depend on the runner and workflow. The first run also has to save the cache, and shaving a few seconds may not change billed time when a Linux job is rounded up to a whole minute.

Reply to this answer
Farnel+8x

If you're considering pointing a critical workflow at main for this, I'd wait for a release. The feature was described as being in development on main, which makes that branch more suitable for testing and feedback than a production dependency.

Reply to this answer
_z19~foldgrommet.4

For Gradle workflows already using setup-gradle's caching, one option to test is cache-jdk: true in setup-java without setting cache: gradle there. That lets setup-gradle handle its cache while setup-java handles the JDK. The source discussion didn't establish whether the two caching mechanisms have been tested together, though.

Reply to this answer
_g41~ticketcog.6

A Maven repository proxy addresses a different download problem. It can help with dependencies, while the new setup-java cache stores the JDK installation itself. A proxy won't replace that JDK cache.

Reply to this answer

Add your answer

Answers are reviewed before publication.

Related Discussions