Skip to content

Instantly share code, notes, and snippets.

@dizzythinks
Created November 10, 2017 10:48
Show Gist options
  • Save dizzythinks/f3bb37fd8ab1484bfec79d39ad8a92d3 to your computer and use it in GitHub Desktop.
Save dizzythinks/f3bb37fd8ab1484bfec79d39ad8a92d3 to your computer and use it in GitHub Desktop.
Read a pom.xml and get version or update it in Python
def managePom(update=False):
from xml.etree import ElementTree as et
ns = "http://maven.apache.org/POM/4.0.0"
et.register_namespace('', ns)
tree = et.ElementTree()
tree.parse('pom.xml')
p = tree.getroot().find("{%s}version" % ns)
if update:
p.text = update
tree.write('pom.xml')
else:
return p.text
@gaborgsomogyi
Copy link

Helped me out, thanks :)

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