Skip to content
Latchkey

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 verify

On 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →