actions/setup-java: Install the JDK in CI
setup-java installs a JDK distribution and can cache Maven or Gradle dependencies.
Pick a distribution (Temurin, Zulu, Corretto, and others) and a Java version, then let setup-java cache your build tool.
Key inputs (with:)
- distribution: temurin, zulu, corretto, microsoft, and more (required).
- java-version: e.g. 17 or 21.
- cache: maven, gradle, or sbt.
- java-package: jdk or jre.
- server-id / settings-path: configure Maven publishing.
Example workflow
.github/workflows/ci.yml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
distribution: temurin
java-version: '21'
cache: maven
- run: mvn -B verifyOn any runner
setup-java runs on any runner. Latchkey managed runners run it unchanged at lower cost.
Key takeaways
- distribution is required; temurin is a common default.
- cache: maven or gradle cuts dependency download time.
- Use server-id and settings to publish artifacts from CI.
Related guides
actions/checkout: Inputs & Workflow UsageReference for actions/checkout: clone your repository into the runner, control fetch-depth, submodules, refs,…
gradle/gradle-build-action: Run Gradle with CachingReference for gradle/gradle-build-action (and its successor actions/setup-gradle): run Gradle builds with dep…