Skip to content

Instantly share code, notes, and snippets.

@crc83
Last active May 14, 2018 22:55
Show Gist options
  • Save crc83/6d3601b22bae0f8e92b1d8539b0a670b to your computer and use it in GitHub Desktop.
Save crc83/6d3601b22bae0f8e92b1d8539b0a670b to your computer and use it in GitHub Desktop.
update property in properties file from gradle script
protected void writeVersion(File file, String key, version) {
if (!file.file) {
project.ant.echo(file: file, message: "$key=$version")
} else {
// we use replace here as other ant tasks escape and modify the whole file
project.ant.replaceregexp(file: file, byline: true) {
regexp(pattern: "^(\\s*)$key((\\s*[=|:]\\s*)|(\\s+)).+\$")
substitution(expression: "\\1$key\\2$version")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment