Skip to content

.java-version file support #113

Closed
Closed

Description

@pavolzbell

Hello, I think it would be nice to set java-version default value by reading .java-version file if it exists, what do you think?

This change is inspired by ruby-setup action which already does the same with .ruby-version file. The use of .java-vesion file is popularized by jenv.

Activity

  1. Fleshgrinder commented on Aug 27, 2021

    @Fleshgrinder

    I'd like to add here that it would be awesome if the content of that file is used by default if present. Basically making the java-version optional. This would lead to zero configuration. 🤩

  2. Fleshgrinder commented on Jan 21, 2022

    @Fleshgrinder

    I found a way to add support for .java-version files that can act as an escape hatch for everyone who wants this functionality today:

        - name: Export .java-version
          run: |
            java_version=11
            if [[ -f .java-version ]]; then
              java_version=$(head -1 .java-version)
            else
              echo "::error file=.java-version::Missing .java-version file, falling back to default Java version: $java_version"
            fi
            echo "JAVA_VERSION=$java_version" >>"$GITHUB_ENV"
        - uses: actions/setup-java@v2
          with:
            distribution: temurin
            java-version: ${{ env.JAVA_VERSION }}

    This can of course be simplified if you use it in a repository where the .java-version file is always guaranteed to exist:

        - name: Export .java-version
          run: echo "JAVA_VERSION=$(head -1 .java-version)" >>"$GITHUB_ENV"
        - uses: actions/setup-java@v2
          with:
            distribution: temurin
            java-version: ${{ env.JAVA_VERSION }}
  3. Fleshgrinder commented on Oct 7, 2022

    @Fleshgrinder

    I got tired and created a wrapping action: https://github.com/Fleshgrinder/setup-java

  4. dmitry-shibanov commented on Feb 8, 2023

    @dmitry-shibanov
    Contributor

    Hello everyone. Sorry for the late response. We released a version of setup-java to pass a .java-version file through the java-version-file input .

  5. IvanZosimov commented on Mar 21, 2023

    @IvanZosimov
    Contributor

    I'm closing this feature request as completed. Related release: https://github.com/actions/setup-java/releases/tag/v3.9.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestNew feature or request to improve the current logic

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions