Skip to content

Instantly share code, notes, and snippets.

@marcingrzejszczak
Last active April 21, 2016 10:18
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 marcingrzejszczak/e63d4985f2a12d51af3310be51b2caa2 to your computer and use it in GitHub Desktop.
Save marcingrzejszczak/e63d4985f2a12d51af3310be51b2caa2 to your computer and use it in GitHub Desktop.
Changes the version of parent
def cli = new CliBuilder(usage:'[options]', header:'Options:')
cli.with {
h longOpt: 'help', 'print this message'
p longOpt: 'pom', args:1, argName:'file', 'Path to POM file to change (required)'
v longOpt: 'version', args:1, argName:'version', 'Version of parent to use (required)'
}
def options = cli.parse(args)
if (!options) {
return
}
if (options.h || !options.p || !options.v) {
cli.usage()
return
}
def pom = new File(options.p)
// to construct slurpring without namespace awareness
def project = new XmlSlurper(false, false).parse(pom)
def parent = project.parent
println "Current Parent: [${parent.groupId}:${parent.artifactId}:${parent.version}]"
println "Changing version to [$options.v]"
parent.version = options.v
println "Changed Parent: [${parent.groupId}:${parent.artifactId}:${parent.version}]"
// store the file back
pom.withWriter { outWriter ->
groovy.xml.XmlUtil.serialize( new groovy.xml.StreamingMarkupBuilder().bindNode(project).toString(), outWriter )
}
println "File changed successfuly!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment