Skip to content

Instantly share code, notes, and snippets.

@smling
Created May 17, 2023 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smling/346417b816a30b8d988a6e945e2f5e8d to your computer and use it in GitHub Desktop.
Save smling/346417b816a30b8d988a6e945e2f5e8d to your computer and use it in GitHub Desktop.
Get maven package latest version
import urllib.request
import xml.etree.ElementTree as ET
repository_url = "https://repo.maven.apache.org/maven2/"
package_name = "org.junit.jupiter.junit-jupiter-api"
metadata_url = repository_url + package_name.replace('.', '/') + "/maven-metadata.xml"
# Send a GET request and retrieve the XML content
with urllib.request.urlopen(metadata_url) as response:
xml_content = response.read()
# Parse the XML content using ElementTree
root = ET.fromstring(xml_content)
# Extract the latest version from the parsed XML
version_tags = root.findall("./versioning/versions/version")
latest_version = version_tags[-1].text # The last version is considered the latest
# Print the latest version
print("Latest version of", package_name, "is", latest_version)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment