Skip to content

Commit ecd2bf1

Browse files
authored
Auto download latest version of custom distribution JDK during run time
1 parent 87c1c70 commit ecd2bf1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

docs/advanced-usage.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,30 @@ steps:
168168
- run: java -cp java HelloWorldApp
169169
```
170170

171+
If your use-case reuires a custom distribution or a version that is not provided by setup-java and always install the latest version during runtime, then you can use below code to auto download the latest JDK, determine the semver needed for the setup-java and setup-java will take care of the installation and caching on the VM:
172+
173+
```yaml
174+
steps:
175+
- name: fetch latest temurin JDK
176+
id: fetch_latest_jdk
177+
run: |
178+
cd $RUNNER_TEMP
179+
response=$(curl -s "https://api.github.com/repos/adoptium/temurin${major_version}-binaries/releases")
180+
latest_jdk_download_url=$(echo "$response" | jq -r '.[0].assets[] | select(.name | contains("jdk_x64_alpine-linux") and endswith(".tar.gz")) | .browser_download_url')
181+
curl -Ls "$latest_jdk_download_url" -o java_package.tar.gz
182+
latest_jdk_json_url=$(jdk_download_url "$response" | jq -r '.[0].assets[] | select(.name | contains("jdk_x64_alpine-linux") and endswith(".tar.gz.json")) | .browser_download_url')
183+
latest_semver_version=$(curl -sL $latest_jdk_json_url | jq -r 'version.semver')
184+
echo "java_version=$latest_semver_version" >> "$GITHUB_OUTPUT"
185+
186+
- uses: actions/setup-java@v3
187+
with:
188+
distribution: 'jdkfile'
189+
jdkFile: ${{ runner.temp }}/java_package.tar.gz
190+
java-version: {{ steps.fetch_latest_jdk.outputs.java_version }}
191+
architecture: x64
192+
- run: java -cp java HelloWorldApp
193+
```
194+
171195
## Testing against different Java distributions
172196
**NOTE:** The different distributors can provide discrepant list of available versions / supported configurations. Please refer to the official documentation to see the list of supported versions.
173197
```yaml

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy