Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.java-version file support #113

Closed
pavolzbell opened this issue Nov 19, 2020 · 5 comments
Closed

.java-version file support #113

pavolzbell opened this issue Nov 19, 2020 · 5 comments
Labels
feature request New feature or request to improve the current logic

Comments

@pavolzbell
Copy link

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.

@Fleshgrinder
Copy link

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. 🤩

@Fleshgrinder
Copy link

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 }}

@Fleshgrinder
Copy link

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

@dmitry-shibanov
Copy link
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 .

@IvanZosimov
Copy link
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
Labels
feature request New feature or request to improve the current logic
Projects
None yet
Development

No branches or pull requests

5 participants