Skip to content

Add output parameter with path to installed JDK #65

Closed

Description

@tbroyer

When calling the action several times, it will overwrite the JAVA_HOME environment variable and prepend it to the PATH, effectively shadowing a previous run of the action.
Fortunately, it will also set a JAVA_HOME_<version>_<architecture> environment variable, but this could be more idiomatic as an output parameter (in addition to the environment variable, which can also be useful on its own: #44 (comment))

This would be a great addition to #21

That way, one could write something like:

- name: Setup JDK 11
  id: setup-java-11
  uses: actions/setup-java@v1
  with:
    java-version: 11
    # here with #21, one would disable "installation"
- name: Setup JDK 14
  id: setup-java-14
  uses: actions/setup-java@v1
  with:
    java-version: 14
    # here with #21, one would disable "installation"
- name: Setup JDK 8
  # Ran last due each run shadowing the previous ones; see also #21
  uses: actions/setup-java@v1
  with:
    java-version: 8
- name: Build and run tests (with JDK 8)
  run: ./gradlew build
- name: Run tests with JDK 11
  run: ./gradlew test -Ptest.jdk-path="${{ steps.setup-java-11.outputs.jdk-path }}"
- name: Run tests with JDK 14
  run: ./gradlew test -Ptest.jdk-path="${{ steps.setup-java-14.outputs.jdk-path }}"

(here, the build is still running with JDK 8, but it coud configure its tests to actually use another JDK)

Activity

  1. tbroyer commented on May 24, 2020

    @tbroyer
    ContributorAuthor

    This is actually worse than that: java-version: 11 won't actually set JAVA_HOME_11_x64, but JAVA_HOME_11.0.7_x64, making that variable essentially useless as its name will actually change whenever a new version of the JDK is released.

    As a workaround, I'm using (with a previous call with java-version: 11 and a previous Gradle build with JDK 11: the new build here still runs with JDK 11 so it won't recompile Java sources)

          # Workaround for https://github.com/actions/setup-java/issues/65
          - name: Backup JAVA_HOME
            id: java-home
            run: echo "::set-output name=path::$JAVA_HOME"

    I could have used a ::set-env too of course to set JAVA_HOME_11_x64.

  2. added 5 commits that reference this issue on May 25, 2020
    d77c93d
    2901684
    2709f77
    141e5bf
    457d7a4
  3. Ryan9Manu commented on Oct 18, 2022

    @Ryan9Manu

    Nmnbbb

  4. Ryan9Manu commented on Oct 18, 2022

    @Ryan9Manu

    Bjjk

  5. Ryan9Manu commented on Oct 18, 2022

    @Ryan9Manu

    Bnnk no nn

    Nn

  6. added a commit that references this issue on Oct 7, 2025
    0d9dabe
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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions