Skip to content

Fleshgrinder/setup-java

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Java Duke Logo
Setup Java

Automatic Java Setup

GitHub Workflow Code Coverage

This is actions/setup-java with sensible defaults that can be changed globally, .java-version file support (resolving #113), and automatic architecture mapping (resolving #375). I created this action, because I am not a fan of copying and pasting things from one project to another, especially not when it comes to workflow automation.

Usage

The example assumes that you have a .java-version file and are fine with the defaults:

jobs:
  example:
    runs-on: ubuntu-latest # All OS are supported!
    steps:
    - uses: actions/checkout@main        # replace @main with desired version
    - uses: fleshgrinder/setup-java@main # replace @main with desired version
    - run: java -version                 # 🎉

The version that was resolved is always exported as JAVA_VERSION to the environment. Subsequent steps can use it to autoconfigure themselves (e.g. Gradle toolchain to use JAVA_VERSION if present, with a fallback to the checked in .java-version file).

This action provides the ability to alter the defaults that have been chosen. This is especially useful for all users of self-hosted runners. Simply include any of the following environment variables in your self-hosted runner to set the default values for all your workflows:

Variable Description
JAVA_DEFAULT_VERSION Version to use if nothing else is present
JAVA_DEFAULT_VERSION_FILENAME Change the .java-version default
JAVA_DEFAULT_DISTRIBUTION Change the temurin default
JAVA_DEFAULT_ARCHITECTURE Disable the $RUNNER_ARCH mapping, can be used to add support for architectures that are not yet supported
JAVA_DEFAULT_PACKAGE_TYPE Change the jdk default
JAVA_DEFAULT_CHECK_LATEST Change the false default

Project Info