actions/setup-java
Install a JDK (Temurin, Zulu, Corretto, and more) and cache Maven or Gradle dependencies.
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
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: maven
- run: mvn -B verifyInputs
| Input | Description | Default | Required |
|---|---|---|---|
distribution | JDK vendor: temurin, zulu, corretto, microsoft, etc. | - | Yes |
java-version | Version, e.g. 17 or 21. | - | No |
java-version-file | Read version from a file such as .java-version. | - | No |
cache | Dependency cache: maven, gradle, or sbt. | - | No |
cache-dependency-path | Path(s) used for the cache key. | auto | No |
Outputs
| Output | Description |
|---|---|
distribution | The distribution that was installed. |
version | The Java version installed. |
path | Path to the JDK (also set as JAVA_HOME). |
cache-hit | true 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: distributionmeans you set onlyjava-version. Adddistribution.- A cache warning means
cacheis 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?
distribution input is required.