Skip to content

Instantly share code, notes, and snippets.

@ahoehma
Created April 5, 2018 09:34
Show Gist options
  • Save ahoehma/a51b7d6a65fe40ad29e3a3defddbd67f to your computer and use it in GitHub Desktop.
Save ahoehma/a51b7d6a65fe40ad29e3a3defddbd67f to your computer and use it in GitHub Desktop.
bash functions to show maven versions
function show_maven_parent_version # pom-file
{
xmllint --xpath "//*[local-name()='parent']/*[local-name()='version']/text()" $1 2>/dev/null
}
function show_maven_project_version # pom-file
{
xmllint --xpath "//*[local-name()='project']/*[local-name()='version']/text()" $1 2>/dev/null
}
function all_poms # no args
{
find . -name "pom.xml" -not -path "*target*" -not -path "*bin*" -print
}
function show_versions
{
for pom in $(all_poms); do
local parent_version=$(show_maven_parent_version $pom)
local project_version=$(show_maven_project_version $pom)
if [[ -n "$parent_version" ]]; then
printf "[parent-version ] %s = %s\n" $parent_version $pom
elif [[ -n "$project_version" ]]; then
printf "[project-version] %s = %s\n" $project_version $pom
else
printf "[not available ] %s\n" $pom
fi
done
}
@ahoehma
Copy link
Author

ahoehma commented Apr 5, 2018

  • if you include these 3 functions into your ~/.bash_profile then you can call show_versions in any maven project
  • if you call show_versions in a maven reactor project the output will show you if a module-version comes from the parent or the module itself
  • you need to install http://xmlsoft.org/xmllint.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment