Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ function get_latest_released_version() {
group_id_url_path="$(sed 's|\.|/|g' <<< "${group_id}")"
url="https://repo1.maven.org/maven2/${group_id_url_path}/${artifact_id}/maven-metadata.xml"
xml_content=$(curl -s --fail "${url}")
latest=$(xmllint --xpath 'metadata/versioning/latest/text()' - <<< "${xml_content}")

# 1. Extract all version tags
# 2. Strip the XML tags to leave just the version numbers
# 3. Filter for strictly numbers.numbers.numbers (e.g., 2.54.0)
# 4. Sort by version (V) and take the last one (tail -n 1)
latest=$(echo "${xml_content}" \
| grep -oE '<version>[0-9]+\.[0-9]+\.[0-9]+</version>' \
| sed -E 's/<[^>]+>//g' \
| sort -V \
| tail -n 1)
Comment on lines +22 to +30
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This pipeline of grep, sed, sort, and tail to find the latest stable version is complex and potentially brittle. A much simpler and more robust approach is to leverage the <release> tag within the maven-metadata.xml file. According to the Maven metadata specification, the <release> tag contains the latest release version, which excludes pre-release versions like RCs and snapshots. This is exactly what's needed here.

You can replace this entire block with a single xmllint command, which is already a dependency for this script.

Suggested change
# 1. Extract all version tags
# 2. Strip the XML tags to leave just the version numbers
# 3. Filter for strictly numbers.numbers.numbers (e.g., 2.54.0)
# 4. Sort by version (V) and take the last one (tail -n 1)
latest=$(echo "${xml_content}" \
| grep -oE '<version>[0-9]+\.[0-9]+\.[0-9]+</version>' \
| sed -E 's/<[^>]+>//g' \
| sort -V \
| tail -n 1)
latest=$(xmllint --xpath 'string(metadata/versioning/release)' - <<< "${xml_content}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The suggestion does not take pre-release versions like -rc into consideration.


if [[ -z "${latest}" ]]; then
echo "The latest version of ${group_id}:${artifact_id} is empty."
echo "The returned json from maven.org is invalid: ${json_content}"
Expand Down
Loading