actions/setup-java@v6

Set up a specific version of the Java JDK and add the command-line tools to the PATH

At a glance

Latest major
v6
Repository
actions/setup-java
Inputs
40 (0 required)
Outputs
5
Runs using
node24
License
MIT
Last checked

Inputs and outputs come straight from the action's official action.yml. See our editorial standards.

Usage

- uses: actions/setup-java@v6

Inputs

NameRequiredDefaultDescription
java-versionNononeThe Java version to set up. Takes a whole or semver Java version, or the "latest" alias to use the newest available stable release. See examples of supported syntax in README file
java-version-fileNononeThe path to a file containing the Java version to set up (.java-version, .tool-versions, .sdkmanrc). Used when java-version is not set. See examples of supported syntax in README file
distributionNononeJava distribution. See the list of supported distributions in README file. This input is required except when java-version-file points to .sdkmanrc with a recognized distribution suffix (e.g., java=21.0.5-tem).
java-packageNojdkThe package type (`jdk`, `jre`, `jdk+fx`, `jre+fx`, `jdk+crac`, `jre+crac`, `jdk+jmods`, `jdk+jcef`, `jre+jcef`, `jdk+ft`, or `jre+ft`). Supported values vary by distribution.
architectureNononeThe architecture of the package (`x86`, `x64`, `armv7`, `aarch64`, `ppc64le`, `ppc64`, `riscv64`, or `s390x`). Aliases `ia32`, `amd64`, `arm`, and `arm64` are normalized to `x86`, `x64`, `armv7`, and `aarch64`. Supported values vary by distribution and operating system. Defaults to the action runner's architecture.
jdk-fileNononePath to where the compressed JDK is located
jdkFileNononeDeprecated The `jdkFile` input is deprecated. Use `jdk-file` instead.
check-latestNofalseSet this option if you want the action to check for the latest available version that satisfies the version spec
force-downloadNofalseSet this option to always download Java and replace any matching version in the tool cache
set-defaultNotrueSet this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.
verify-signatureNononeCheck downloaded Java package signatures when supported by the selected distribution. When omitted, failures produce warnings. Explicitly setting this to true enforces verification and makes failures fatal, including failures caused by an unexpected vendor signing-key rotation.
verify-signature-public-keyNononeOne or more ASCII-armored GPG public keys used to verify downloaded package signatures. Concatenate multiple armored key blocks. Custom keys replace the bundled keys for the selected distribution.
server-idNogithubID of the distributionManagement repository in the pom.xml file. Default is `github`
server-username-env-varNononeEnvironment variable name for the username for authentication to the Apache Maven repository. Default is $GITHUB_ACTOR
server-usernameNononeDeprecated alias for server-username-env-var
server-password-env-varNononeEnvironment variable name for password or token for authentication to the Apache Maven repository. Default is $GITHUB_TOKEN
server-passwordNononeDeprecated alias for server-password-env-var
mvn-server-credentialsNononeMultiline list of Maven server credentials in the format `server-id:USERNAME_ENV:PASSWORD_ENV`. When set, replaces the single server configured by server-id, server-username-env-var, and server-password-env-var.
mvn-server-repository-originsNononeMultiline list of Maven credential origins in the format `server-id:repository-origin`. Each origin must belong to a configured server ID. Requires Maven 3.10+.
mvn-repositoriesNononeMultiline list of Maven dependency repositories in the format `repository-id:repository-url:snapshots-enabled`.
mvn-plugin-repositoriesNononeMultiline list of Maven plugin repositories in the format `repository-id:repository-url:snapshots-enabled`.
mvn-mirrorsNononeMultiline list of Maven mirrors in the format `mirror-id:mirror-url:mirror-of`. The URL must include a scheme; percent-encode colons in its path, query, or fragment. Use a matching server ID for authentication. Can be used independently of repository inputs.
mvn-repositories-include-centralNotrueInclude Maven Central for dependency and plugin repositories in the generated profile. When false, Central is disabled for both types unless that type explicitly declares ID `central`. Has no effect when neither repository list is configured.
mvn-repositories-prioritize-centralNotruePlace Maven Central before custom dependency and plugin repositories. Has no effect when Maven Central is excluded or neither repository list is configured.
settings-pathNononePath to where the settings.xml file will be written. Default is ~/.m2.
overwrite-settingsNotrueOverwrite the settings.xml file if it exists. Default is "true".
gpg-private-keyNononeGPG private key to import into an isolated temporary keyring. Default is empty string.
gpg-passphrase-env-varNononeEnvironment variable name for the GPG private key passphrase. Defaults to GPG_PASSPHRASE when gpg-private-key is set.
gpg-passphraseNononeDeprecated alias for gpg-passphrase-env-var
cacheNononeName of the build platform to cache dependencies. It can be "maven", "gradle" or "sbt".
cache-jdkNononeCache downloaded JDK installations between jobs. Defaults to enabled when dependency caching is configured with `cache`; set explicitly to "true" or "false" to override.
cache-dependency-pathNononeThe path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.
cache-pathNononeThe path to cache instead of the default dependency cache path for the selected package manager. This option can be used with the `cache` option and supports a list of paths and exclusion patterns.
cache-read-onlyNofalseRestore caches without saving cache changes in the post action.
job-statusNo${{ job.status }}Workaround to pass job status to post job step. This variable is not intended for manual setting
tokenNo${{ github.server_url == 'https://github.com' && github.token || '' }}The token used to authenticate when fetching version manifests hosted on github.com, such as for the Microsoft Build of OpenJDK. When running this action on github.com, the default value is sufficient. When running on GHES, you can pass a personal access token for github.com if you are experiencing rate limiting.
mvn-toolchain-idNononeName of Maven Toolchain ID if the default name of "${mvn-toolchain-vendor}_${java-version}" is not wanted. The toolchain vendor defaults to the "distribution" input. When supplied, the number of IDs must match the number of Java versions. See examples of supported syntax in Advanced Usage file
mvn-toolchain-vendorNononeName of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file
show-download-progressNofalseWhether Maven should print artifact download/transfer progress to the build log. When "false" (default) the action sets "-ntp" (--no-transfer-progress) in MAVEN_ARGS to produce cleaner logs. Set to "true" to keep the progress output. Has no effect on non-Maven builds.
problem-matcherNofalseWhether to register the Java problem matcher (compiler errors/warnings and uncaught exceptions). Disabled by default; set to "true" to enable annotations.

Outputs

NameDescription
distributionDistribution of Java that has been installed
versionActual version of the java environment that has been installed
pathPath to where the java environment has been installed (same as $JAVA_HOME)
cache-hitA boolean value to indicate an exact match was found for the primary key
cache-primary-keyThe primary cache key computed by the action for the configured build tool. Empty when caching is not enabled or when caching is skipped (e.g. cache service unavailable). Useful for composing with actions/cache or actions/cache/restore across jobs.

Read an output with ${{ steps.<step-id>.outputs.<name> }}; the step needs an id.

Examples

Temurin 21 with Maven cache

Install a JDK distribution and cache the Maven repository.

name: Example
on:
  push:
    branches: [main]

permissions:
  contents: read

jobs:
  example:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - name: Setup Java JDK
        uses: actions/setup-java@v6
        with:
          distribution: temurin
          java-version: 21
          cache: maven
      - run: mvn --batch-mode verify

Each example passed actionlint (syntax, expressions and the inputs it knows for this action). They were not run in a live repository, so replace placeholder values such as names, ARNs and paths with your own.

Something out of date or wrong? Report it on our Contact page. This page is rebuilt from the action's repository roughly once a week.