Created
May 17, 2023 08:25
-
-
Save smling/346417b816a30b8d988a6e945e2f5e8d to your computer and use it in GitHub Desktop.
Get maven package latest version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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