Skip to content
Latchkey

actions/setup-java

Install a JDK (Temurin, Zulu, Corretto, and more) and cache Maven or Gradle dependencies.

Official actionCategory: Language & Toolchain SetupLatest v4View on GitHub

What it does

actions/setup-java installs a JDK from a chosen vendor distribution and exposes java/javac on PATH, and it can cache the Maven or Gradle dependency directory.

Unlike setup-node, the distribution input is required: you pick the vendor (for example temurin, zulu, corretto).

Usage

workflow (.yml)
steps:
  - uses: actions/checkout@v4
  - uses: actions/setup-java@v4
    with:
      distribution: temurin
      java-version: '21'
      cache: maven
  - run: mvn -B verify

Inputs

InputDescriptionDefaultRequired
distributionJDK vendor: temurin, zulu, corretto, microsoft, etc.-Yes
java-versionVersion, e.g. 17 or 21.-No
java-version-fileRead version from a file such as .java-version.-No
cacheDependency cache: maven, gradle, or sbt.-No
cache-dependency-pathPath(s) used for the cache key.autoNo

Outputs

OutputDescription
distributionThe distribution that was installed.
versionThe Java version installed.
pathPath to the JDK (also set as JAVA_HOME).
cache-hittrue if an exact dependency cache was restored.

Notes

distribution is required. Use cache: maven or cache: gradle to reuse dependencies between runs.

Common errors

  • Input required and not supplied: distribution means you set only java-version. Add distribution.
  • A cache warning means cache is set but no pom.xml/build.gradle was found where expected.

Security and pinning

  • Pin setup-java to a commit SHA.

Frequently asked questions

Which Java distribution should I pick?
temurin (Eclipse Adoptium) is a common default. corretto, zulu, and microsoft are also supported. The distribution input is required.

References

Running actions/setup-java? Run it on Latchkey managed runners - self-healing and caching included. Start free → 30-day trial · No credit card