镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

how do i use the "install-multiple-jdks" in the Github action #586

Closed

Description

@angold5

Description:
How do i use the new version of java in the github action
https://github.com/actions/setup-java#install-multiple-jdks

    steps:

        uses: actions/setup-java@v4
        with:
          distribution: '<distribution>'
          java-version: 17
      - run: java HelloWorldApp.java
      - name: Sonar scan
        env:
          SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
        run: ./gradlew build sonar --info
working-directory: ./my-app/HelloWorldFunction

Justification:
i dont know how to use it

Are you willing to submit a PR?

Activity

  1. v-aparnajyothi-y commented on Jan 16, 2024

    @v-aparnajyothi-y
    Contributor

    Hello @angold5
    Thank you for reporting this issue, We will investigate it and come back to you as soon as we have some information.

  2. AndreiLepkovTR commented on Jan 29, 2025

    @AndreiLepkovTR

    I cannot assign JAVA_HOME variable to switch Java versions. It shows empty value. How it should be done?

          - name: Set up multiple JDKs
            uses: actions/setup-java@v4
            with:
              distribution: 'corretto'
              java-version: |
                21
                11
          - name: Some java work that requires JAVA 21
            env:
              JAVA_HOME: ${{ env.JAVA_HOME_21_x64 }}
            run: java HelloWorldApp.java
    
  3. added
    questionFurther information is requested
    and removed
    feature requestNew feature or request to improve the current logic
    on Jun 22, 2026
  4. brunoborges commented on Jun 23, 2026

    @brunoborges
    Contributor

    This is a usage question, so answering and closing it here. To install multiple JDKs and have a later step use a specific one, pass a multi-line java-version — setup-java installs each and exports JAVA_HOME_<major>_<arch> for every version (the last one becomes the active JAVA_HOME/PATH):

    steps:
      - uses: actions/setup-java@v4
        with:
          distribution: 'temurin'
          java-version: |
            8
            11
            17
      - name: Use Java 11 explicitly
        run: \$JAVA_HOME_11_X64/bin/java -version
      - name: Default (last installed = 17)
        run: java -version

    See the docs: https://github.com/actions/setup-java?tab=readme-ov-file#install-multiple-jdks

    Note: this installs multiple versions of one distribution. Installing multiple distributions in one step is a separate feature request, now tracked in #1049. For questions, the GitHub Actions community discussions are also a good venue.

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

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions