Last active
April 21, 2016 10:18
-
-
Save marcingrzejszczak/e63d4985f2a12d51af3310be51b2caa2 to your computer and use it in GitHub Desktop.
Changes the version of parent
This file contains hidden or 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
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