Set up your GitHub Actions workflow with a specific version of Java
Repo actions/setup-java, read from GitHub 1 min ago. actions has not joined Take My Repo.
actions/setup-java is a public repo on GitHub by actions. Set up your GitHub Actions workflow with a specific version of Java. It declares the MIT license on GitHub. It is written mainly in TypeScript, has 2,033 stars and last changed on 2026-11-18. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-19.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
Set up Java for GitHub Actions workflows. setup-java installs a requested Java distribution, adds it to PATH, configures JAVA_HOME, and can optionally cache build dependencies for Apache Maven, Gradle, and sbt; generate Maven publishing configuration, verify JDK package signatures, manage multiple JDKs, and manage Maven toolchains.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' - run: java --version
latest stable release alias.settings.xml, Maven Toolchains, Maven GPG signing inputs, and environment-variable based credentials for publishing workflows.setup-java works with Java, Scala, Kotlin, Gradle, Maven, and sbt projects.
@actions/* packages.oracle-openjdk), Red Hat Build of OpenJDK (redhat), and Liberica Native Image Kit (liberica-nik), and expanded Tencent Kona support through JDK 25.java-version: latest to resolve the newest stable GA release from the distribution's remote metadata.18.0.1.1, Temurin jdk+jmods packages, and native musl artifacts on Alpine for Dragonwell, Corretto, Zulu, and Liberica.force-download: true to bypass the tool cache and perform a reproducible fresh install.cache-path and restore-only operation with cache-read-only: true..mvn/extensions.xml and gradle.properties, preventing stale restores when Maven extensions or Gradle dependency properties change.cache is set; use cache-jdk to enable or disable it independently.problem-matcher: true to enable them.GRAALVM_HOME in addition to JAVA_HOME.server-username -> server-username-env-varserver-password -> server-password-env-vargpg-passphrase -> gpg-passphrase-env-vargpg.passphraseEnvName instead of a deprecated gpg.passphrase server entry in settings.xml. This requires maven-gpg-plugin 3.2.0 or newer. See GPG.temurin instead of adopt or adopt-hotspot, and semeru instead of adopt-openj9.v2.327.1 or later. See the runner release notes.java-version-file support with .sdkmanrc files and automatic distribution detection from SDKMAN and asdf vendor identifiers.set-default: false for installing a JDK without changing JAVA_HOME or PATH.cache-primary-key output.javac compiler errors.jdkFile input to jdk-file; the old name remains available as a deprecated alias.Warning
actions/setup-java versions v1 through v4 are deprecated. Upgrade workflows to actions/setup-java@v6, the latest stable release.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' - run: java --version
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: microsoft java-version: '25' - run: java --version
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version-file: .java-version - run: java --version
Supported version files are .java-version, .tool-versions, and .sdkmanrc. A .sdkmanrc file can also provide the distribution when it contains a recognized suffix, such as java=21.0.5-tem.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: latest - run: java --version
latest resolves the newest stable GA release from remote metadata rather than from the runner tool cache. Distributions that do not publish a release listing (such as oracle and graalvm) resolve the newest GA feature version from the Adoptium available-releases API and then request that version from their own catalog. latest is not supported with java-version-file, early-access versions, or distribution: jdkfile.
| Input | Description | Default |
|---|---|---|
java-version |
Java version to install. Supports whole versions, semver ranges, early-access versions, and latest. Required unless java-version-file is set. |
|
java-version-file |
Path to .java-version, .tool-versions, or .sdkmanrc. Used when java-version is not set. |
|
distribution |
Java distribution keyword. Values are case-sensitive and must match one of the supported keywords below. Required unless java-version-file points to .sdkmanrc with a recognized distribution suffix. |
|
java-package |
Package variant such as jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac, jdk+jmods, jdk+jcef, jre+jcef, jdk+ft, or jre+ft. Support varies by distribution. |
jdk |
architecture |
Package architecture. Canonical values are x86, x64, armv7, aarch64, ppc64le, ppc64, riscv64, and s390x. Aliases ia32, amd64, arm, and arm64 are normalized. |
Runner architecture |
jdk-file |
Local compressed JDK archive. Requires distribution: jdkfile. |
|
check-latest |
Check remote metadata for the latest version satisfying the version spec before using the runner tool cache. | false |
force-download |
Always download Java and replace any matching version in the tool cache. | false |
set-default |
Add Java to PATH and set JAVA_HOME. When false, only version-specific JAVA_HOME_<major>_<arch> variables are set. |
true |
problem-matcher |
Register Java compiler and uncaught exception problem matchers. | false |
verify-signature |
Verify downloaded Java package signatures when supported. Explicitly setting this to true makes verification failures fatal. |
Distribution-dependent; see Download integrity and signatures |
verify-signature-public-key |
One or more ASCII-armored GPG public keys used for signature verification. Concatenate multiple armored key blocks. Custom keys replace the bundled distribution keys. | |
token |
Token for fetching GitHub.com-hosted version manifests, useful on GitHub Enterprise Server when unauthenticated requests are rate-limited. | ${{ github.token }} on GitHub.com; empty string on GHES |
cache |
Enable dependency caching for maven, gradle, or sbt. |
|
cache-jdk |
Cache downloaded JDK installations between jobs. When omitted, JDK caching is enabled only if cache is set. Set explicitly to true or false to override. |
Enabled when cache is set |
cache-dependency-path |
Dependency file paths used for cache key hashing. Supports globs and multiline values. | Auto-detected by package manager |
cache-path |
Cache paths to use instead of the package manager's default dependency cache path. Supports multiline values and exclusions. | |
cache-read-only |
Restore dependency, wrapper, and JDK caches without saving changes in the post step. | false |
server-id |
Maven repository ID used in generated settings.xml. |
github |
server-username-env-var |
Environment variable name for Maven repository username. | GITHUB_ACTOR |
server-password-env-var |
Environment variable name for Maven repository password or token. | GITHUB_TOKEN |
mvn-server-credentials |
Multiline Maven server credentials in the format server-id:USERNAME_ENV:PASSWORD_ENV. Replaces the single server configured by the three inputs above when set. |
|
mvn-server-repository-origins |
Multiline Maven credential origins in the format server-id:repository-origin. Each origin must belong to a configured server ID. Requires Maven 3.10+. |
|
mvn-repositories |
Multiline Maven dependency repositories in the format repository-id:repository-url:snapshots-enabled. |
|
mvn-plugin-repositories |
Multiline Maven plugin repositories in the format repository-id:repository-url:snapshots-enabled. Can be used independently of mvn-repositories. |
|
mvn-mirrors |
Multiline Maven mirrors in the format mirror-id:mirror-url:mirror-of. Redirect matching dependency and plugin repositories; use a matching server ID for authentication. |
|
mvn-repositories-include-central |
Include Maven Central for dependency and plugin repositories in the generated profile. When false, Central is disabled for both types unless that type explicitly declares central. Has no effect when neither repository list is configured. |
true |
mvn-repositories-prioritize-central |
Place Maven Central before custom dependency and plugin repositories. Has no effect when Central is excluded or neither repository list is configured. | true |
settings-path |
Directory where settings.xml is written. |
~/.m2 |
overwrite-settings |
Overwrite an existing settings.xml. |
true |
gpg-private-key |
GPG private key to import into an isolated temporary keyring. | |
gpg-passphrase-env-var |
Environment variable name for the GPG private key passphrase. | GPG_PASSPHRASE when a key is set |
mvn-toolchain-id |
Maven Toolchain ID. When multiple Java versions are installed, the number of IDs must match the number of versions. | ${mvn-toolchain-vendor}_${java-version} |
mvn-toolchain-vendor |
Maven Toolchain vendor value. | ${distribution} |
show-download-progress |
Keep Maven artifact download and transfer progress in logs. When false, the action adds -ntp to MAVEN_ARGS. |
false |
java-package: Supported package types are jdk, jre, jdk+fx, jre+fx, jdk+crac, jre+crac, jdk+jmods, jdk+jcef, jre+jcef, jdk+ft, and jre+ft. Availability varies by distribution.Deprecated aliases jdkFile, server-username, server-password, and gpg-passphrase remain accepted for compatibility, but should be replaced with the current input names.
| Output | Description |
|---|---|
distribution |
Distribution that was installed. |
version |
Actual Java version that was installed. |
path |
Installation path, also used for JAVA_HOME when set-default is enabled. |
cache-hit |
Whether an exact dependency cache match was restored. |
cache-primary-key |
Primary cache key computed for the selected package manager. Empty when caching is disabled or skipped. |
| Keyword | Distribution | License |
|---|---|---|
corretto |
Amazon Corretto | License |
dragonwell |
Alibaba Dragonwell JDK | License |
graalvm |
Oracle GraalVM | License |
graalvm-community |
GraalVM Community | License |
jetbrains |
JetBrains Runtime | License |
kona |
Tencent Kona JDK | License |
liberica |
Liberica JDK | License |
liberica-nik |
Liberica Native Image Kit | License |
microsoft |
Microsoft Build of OpenJDK | License |
oracle |
Oracle JDK | License |
oracle-openjdk |
Oracle OpenJDK | License |
redhat |
Red Hat Build of OpenJDK | License |
sapmachine |
SAP SapMachine JDK/JRE | License |
semeru |
IBM Semeru Runtime Open Edition | License |
temurin |
Eclipse Temurin | License |
zulu |
Azul Zulu OpenJDK | License |
jdkfile |
Custom JDK archive |
Note
Distribution availability, package variants, architectures, and version metadata differ by vendor. Check the vendor documentation when a specific version or platform matters.
Additional distribution notes:
arm64 to aarch64 when querying the Azul Metadata API.25.0.5.0.2 can also be requested as 25.0.5+0.2.distribution: graalvm-community for stable JDK 17 and later releases.sudo do not inherit the JAVA_HOME and PATH set by setup-java and may fall back to the system-default JDK.java-version accepts exact versions, version ranges, early-access versions, and latest.
| Syntax | Examples |
|---|---|
| Major version | 8, 11, 17, 21, 25 |
| Specific feature or patch version | 11.0, 11.0.4, 17.0, 8.0.282+8 |
| JEP 322 multi-field versions | 11.0.9.1, 18.0.1.1, 26.0.2.1+1 |
| Early access | 15-ea, 15.0.0-ea, 27-ea |
| Latest stable GA release | latest |
When check-latest is false, the action first tries the runner tool cache for the requested distribution, package type, architecture, and version range. It downloads Java only when no matching cached version is found. When check-latest is true, the action checks remote metadata first and downloads if the cached version is not current.
GitHub-hosted runners primarily pre-cache Eclipse Temurin JDKs. See the installed Java versions for Ubuntu, Windows, and macOS. On a fresh GitHub-hosted runner, requests for other distributions usually miss the tool cache and resolve from remote metadata. For broad version ranges such as a major version (21, 25), this often behaves similarly to check-latest: true because the action downloads the latest available release that satisfies the range.
To see which exact version a request resolves to today, open the summary of the latest run of the daily Latest JDK versions report workflow. For every supported distribution, it lists the version that setup-java currently resolves from vendor metadata for every major from Java 6 through the newest stable GA release (including non-LTS releases), plus latest, on every operating system and architecture the action supports for that distribution, including Alpine Linux and Solaris. Because vendors publish builds per platform, the same request can resolve to different versions on different platforms. The report doesn't download any JDKs. Floating vendor URLs are marked when their exact version cannot be established from metadata alone. It shows what a job installs on a tool-cache miss or with check-latest: true.
setup-java automatically verifies downloaded archive checksums when a selected distribution publishes an authoritative checksum. Automatic checksum verification currently applies to temurin, semeru, corretto, dragonwell, kona, sapmachine, graalvm, graalvm-community, zulu, oracle, oracle-openjdk, microsoft, and jetbrains.
Distributions or individual releases without an authoritative checksum continue to install normally, with the omission reported in debug logs. Installations resolved directly from the runner tool cache — including JDKs preinstalled on the runner image and JDKs installed by an earlier step of the same job — are not downloaded again and are not reverified, even when verify-signature: true is set. Use force-download: true to always download and verify the archive.
Package signature verification is supported for temurin and microsoft. When verify-signature is omitted, the action checks the signature and warns if GPG is unavailable or verification fails, but does not enforce the result. Explicitly setting verify-signature: true enforces verification and makes these failures fatal. Setting verify-signature: true for an unsupported distribution also fails the workflow.
Warning
Requesting explicit signature verification with verify-signature can fail a build after an unexpected but legitimate vendor signing-key rotation, because the action's bundled keys may not yet include the new key. Confirm a new key through the vendor's trusted documentation before using it.
After confirming a legitimate rotation, configure the updated key with verify-signature-public-key. The input accepts one or more ASCII-armored public keys; concatenate complete armored key blocks when both old and new vendor keys are needed during a transition. Custom keys replace, rather than extend, the keys bundled with the selected distribution.
- uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' verify-signature: true verify-signature-public-key: | -----BEGIN PGP PUBLIC KEY BLOCK----- ...vendor key material... -----END PGP PUBLIC KEY BLOCK-----
As a temporary fallback while a legitimate rotation is being investigated, set verify-signature: false. This disables package signature verification, although authoritative checksum verification still applies when the vendor publishes a checksum.
- uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' verify-signature: false
setup-java manages three kinds of caches. Each one is restored and saved as a separate cache entry.
| Cache | What it stores | Key based on | How it is enabled |
|---|---|---|---|
| Dependency cache | Downloaded dependencies, such as ~/.m2/repository, ~/.gradle/caches, or the sbt cache paths |
Runner OS, architecture, package manager, and a hash of the dependency files | Set cache to maven, gradle, or sbt |
| Wrapper caches | Maven and Gradle wrapper distributions (~/.m2/wrapper/dists, ~/.gradle/wrapper) |
Runner OS, architecture, wrapper cache name, and a hash of the wrapper properties | Set cache to maven or gradle |
| JDK cache | The downloaded JDK installation | Runner OS, architecture, distribution, package type, resolved version, release identity, and signature-verification identity | Enabled implicitly whenever cache is set, or explicitly with cache-jdk: true. Opt out with cache-jdk: false |
Set cache to maven, gradle, or sbt to cache dependencies with minimal configuration.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: maven - run: mvn verify
The primary dependency cache key is setup-java-<runner-os>-<node-arch>-<package-manager>-<file-hash>, where <node-arch> is the runner's Node.js process architecture. The primary cache stores dependency directories such as ~/.m2/repository, ~/.gradle/caches, or the sbt cache paths. Its file hash is based on these files by default:
| Package manager | Files used for the primary dependency-cache key |
|---|---|
| Gradle | **/*.gradle*, **/gradle.properties, **/gradle-wrapper.properties, buildSrc/**/Versions.kt, buildSrc/**/Dependencies.kt, gradle/*.versions.toml, **/versions.properties |
| Maven | **/pom.xml, **/.mvn/wrapper/maven-wrapper.properties, **/.mvn/extensions.xml |
| sbt | **/*.sbt, **/project/build.properties, **/project/**.scala, **/project/**.sbt |
Use cache-dependency-path to override the files used for key hashing, especially in monorepos:
- uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: gradle cache-dependency-path: | sub-project/*.gradle* sub-project/**/gradle-wrapper.properties
Use cache-path when the build tool stores dependencies outside the default location:
- uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: maven cache-path: | /custom/maven/repository !/custom/maven/repository/**/*.lastUpdated - run: mvn -Dmaven.repo.local=/custom/maven/repository verify
cache-path changes what is restored and saved, but not the cache key. Jobs that should share a cache key must use the same OS, architecture, package manager, dependency files, and cache paths.
Maven and Gradle wrapper distributions are restored and saved as additional cache entries, separate from the primary dependency cache. These entries have their own keys in the form setup-java-<runner-os>-<node-arch>-<wrapper-cache-name>-<file-hash>.
| Package manager | Wrapper cache name | Cached path | Files used for wrapper-cache key |
|---|---|---|---|
| Maven | maven-wrapper |
~/.m2/wrapper/dists |
**/.mvn/wrapper/maven-wrapper.properties |
| Gradle | gradle-wrapper |
~/.gradle/wrapper |
**/gradle-wrapper.properties |
These wrapper caches are independent from dependency caches, so they remain useful even when dependency files change frequently. The wrapper properties are also part of the Maven and Gradle primary dependency-cache key because wrapper changes can affect how dependencies are resolved, but the wrapper distribution files themselves are stored in the separate wrapper cache entries above.
For advanced Gradle caching features such as build output caching, configuration cache support, encrypted cache storage, cleanup, and fine-grained cache control, consider gradle/actions/setup-gradle.
The JDK cache stores the downloaded JDK installation so later runs skip the download. It is enabled implicitly whenever dependency cache is set, so most workflows that cache dependencies are already caching the JDK. Set cache-jdk: true to enable it without dependency caching, or cache-jdk: false to opt out while keeping dependency caching. With neither cache nor cache-jdk set, nothing is cached.
Important
Because JDK caching is on by default whenever cache is set, review Caching JDK installations
for the full cache/cache-jdk matrix, cache identity and storage impact.
Set cache-read-only: true to restore dependency, wrapper, and JDK caches without saving changes in the post action. This is useful for pull requests, merge queues, short-lived branches, and matrix fan-out jobs that should only consume caches produced elsewhere.
- uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: maven cache-read-only: ${{ github.ref != 'refs/heads/main' }}
For matrix fan-out, seed the cache once and make matrix jobs read-only consumers:
jobs: seed-cache: runs-on: ubuntu-latest steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: maven - run: mvn dependency:go-offline dependency:resolve-plugins build: needs: seed-cache runs-on: ubuntu-latest strategy: matrix: goal: [test, verify, package] steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: maven cache-read-only: true - run: mvn ${{ matrix.goal }}
Cache downloads are split into segments. To reduce the chance of a stuck segment blocking a workflow, set SEGMENT_DOWNLOAD_TIMEOUT_MINS:
env: SEGMENT_DOWNLOAD_TIMEOUT_MINS: '5' steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' cache: gradle - run: ./gradlew build --no-daemon
Install multiple Java versions by providing a multiline java-version value. All configured JDKs are installed. The last one added to PATH becomes the default.
steps: - uses: actions/setup-java@v6 with: distribution: temurin java-version: | 8 11 17 21 25
Other installed JDKs are available through version-specific variables such as JAVA_HOME_17_X64. To use a specific version later in the job, set JAVA_HOME and prepend its bin directory to PATH.
setup-java writes a Maven Toolchains declaration for each installed JDK. When multiple JDKs are installed, the declaration contains all of them. Customize the generated toolchain values with mvn-toolchain-id and mvn-toolchain-vendor.
jobs: build: runs-on: ubuntu-latest strategy: matrix: java: ['8', '11', '17', '21', '25'] name: Java ${{ matrix.java }} steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: ${{ matrix.java }} - run: java --version - run: mvn verify
setup-java generates Maven settings.xml and Maven Toolchains configuration. For Gradle publishing, it installs Java for the workflow; the Gradle build file remains responsible for reading credentials from environment variables.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' server-id: github server-username-env-var: GITHUB_ACTOR server-password-env-var: GITHUB_TOKEN - run: mvn --batch-mode deploy env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
For dependencies hosted outside Maven Central, use mvn-repositories; for build
plugins, use mvn-plugin-repositories. Either input adds its own repository type
to the same active profile in the generated settings.xml. Repository IDs can
match mvn-server-credentials IDs when authentication is required.
See Resolving Maven dependencies from custom repositories
and Resolving Maven plugins from custom repositories.
To redirect repositories, including Central and repositories declared in project
or parent POMs, use mvn-mirrors.
It works independently of the repository inputs; a mirrorOf pattern of *
routes all dependency and plugin repositories through the configured mirror.
Warning
mvn-repositories-include-central: false now disables inherited Maven Central
for both dependencies and plugins, even in existing workflows that only
configure mvn-repositories. Builds relying on uncached plugins from Central
must configure mvn-plugin-repositories with an accessible plugin repository
or explicitly declare central there. Neither repository list configured
means the Central controls remain inactive.
steps: - uses: actions/checkout@v7 - uses: actions/setup-java@v6 with: distribution: temurin java-version: '25' gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }} gpg-passphrase-env-var: GPG_PASSPHRASE - run: mvn --batch-mode deploy env: GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
Maven GPG signing requires maven-gpg-plugin 3.2.0 or newer because setup-java passes the passphrase through gpg.passphraseEnvName.
When using the setup-java action in your GitHub Actions workflow, it is recommended to set the following permissions to ensure proper functionality:
permissions: contents: read # access to check out code and install dependencies
Publishing workflows may require additional permissions depending on the target registry.
See advanced usage for detailed examples:
The scripts and documentation in this project are released under the MIT License.
Contributions are welcome. See our Contributor's Guide.
👋 Be nice. See our code of conduct
actions/setup-java is a public repo on GitHub by actions. Set up your GitHub Actions workflow with a specific version of Java.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-18. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Accelerating new GitHub Actions workflows
Kubernetes controller for GitHub Actions self-hosted runners
This page is also available as structured data, with the same sources and dates.
/api/v1/resources/gh/actions/setup-javaTake My Repo has not tested this on your machine. Requirements come from the project's own documentation.