Using Eclipse Temurin in GitHub Actions

The actions/setup-java action is the recommended way to install Eclipse Temurin in GitHub Actions workflows. It handles downloading, caching, and configuring the JDK on the runner.

Basic Usage

To set up Eclipse Temurin in a workflow, add the following step:

Note

The action versions shown in these examples may not always reflect the latest releases. Check the actions/setup-java releases and actions/checkout releases for the most up-to-date versions. The Adoptium project recommends pinning actions to full commit SHAs rather than version tags for improved security and reproducibility.

steps:
  - uses: actions/checkout@v6
  - uses: actions/setup-java@v5
    with:
      distribution: 'temurin'
      java-version: '25'
  - run: java --version

The distribution must be set to temurin and java-version specifies which major version to install.

Testing Against Multiple Java Versions

Use a matrix strategy to test your project against multiple Java versions:

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        java: [ '11', '17', '25' ]
    name: Java ${{ matrix.java }}
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-java@v5
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java }}
      - run: java --version

Caching Dependencies

The setup-java action has built-in support for caching dependencies managed by Maven, Gradle, and sbt.

Caching Maven Dependencies

steps:
  - uses: actions/checkout@v6
  - uses: actions/setup-java@v5
    with:
      distribution: 'temurin'
      java-version: '25'
      cache: 'maven'
  - run: mvn -B package

Caching Gradle Dependencies

steps:
  - uses: actions/checkout@v6
  - uses: actions/setup-java@v5
    with:
      distribution: 'temurin'
      java-version: '25'
      cache: 'gradle'
  - run: ./gradlew build

Caching sbt Dependencies

steps:
  - uses: actions/checkout@v6
  - uses: actions/setup-java@v5
    with:
      distribution: 'temurin'
      java-version: '25'
      cache: 'sbt'
  - run: sbt package

Complete Workflow Example

Here is a complete workflow that builds and tests a Maven project using Eclipse Temurin across multiple Java versions:

name: Build and Test

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

permissions:
  contents: read

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        java: [ '11', '17', '25' ]
    name: Build with Java ${{ matrix.java }}
    steps:
      - uses: actions/checkout@v6
      - name: Set up JDK ${{ matrix.java }}
        uses: actions/setup-java@v5
        with:
          distribution: 'temurin'
          java-version: ${{ matrix.java }}
          cache: 'maven'
      - name: Build with Maven
        run: mvn -B package --file pom.xml

Using the Latest Version

Set check-latest: true to always download the most up-to-date version available, rather than relying on the cached version on the runner:

- uses: actions/setup-java@v5
  with:
    distribution: 'temurin'
    java-version: '25'
    check-latest: true

Note

Setting check-latest to true has performance implications as downloading a JDK is slower than using cached versions.

Installing Multiple JDKs

You can install multiple JDK versions in a single job. The last version configured will be the default on PATH:

steps:
  - uses: actions/setup-java@v5
    with:
      distribution: 'temurin'
      java-version: |
        11
        17
        25

Other Java versions can be accessed through environment variables such as JAVA_HOME_11_X64, JAVA_HOME_17_X64, etc.

edit icon

Help us make these docs great!

All Adoptium docs are open source. See something that's wrong or unclear?

Documentation Authors
gdams
Join our Slack channel to discuss and reach out to maintainers.Join Slack