How to get the available jdk versions in install-jdk library of python?

31 Views Asked by At

I want to get all the jdk versions that available/supported for the time. I know the install-jdk library, but I think there's no function to get them, or I didn't notice. Do you know a way to get the jdk versions that the install-jdk can install?

import jdk

# like the example:
jdk.install("11")

but I want something like this:

versions = jdk.get_available_versions()
print(versions)

But there's not such a function I think..

2

There are 2 best solutions below

0
Stephen C On BEST ANSWER

The short answer is that you can't.

If you look at the code, you will see that the Client classes actually don't know what the available versions are. Rather, they all1 just assemble a URL for the downloadable using whatever the caller provided as the version string, and then just attempt to connect to that URL.

Given that web servers are not file systems, there is probably not a simple way (i.e. without gnarly webpage scraping) to query the download sites to find all available versions. (But ... hey ... there's nothing stopping you from trying.)


1 - ... at the time of writing

2
rochard4u On

The default vendor (source) is Adoptium.

Adoptium support the following version (https://adoptium.net/fr/temurin/releases/): 8-LTS, 11-LTS, 16, 17-LTS, 18, 19, 20, 21-LTS.

versions = jdk.get_available_versions()
# Is equivalent to
versions = ["8", "11", "16", "17", "18", "19", "20", "21"]

Edit: Following Stephen's comment, here is what I think is a more sustainable approach:

You could parse the result to a call to the Adoptium API getting all available releases.

import requests

url = "https://api.adoptium.net/v3/info/available_releases"
headers = {
  'content-type': 'application/json',
  'Accept-Charset': 'UTF-8',
  'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'
}
response = requests.get(url, headers=headers)
print(response.text)

This gets you a JSON that you could then parse into a list if you want.