I’m quite new to Gradle and I’m trying to write a task which will read my version number from a file, increment it, and write it to the same file (not sure if this is the best approach, I’m happy to listen to advice on this too).
def versionFile = new File("src/main/java/version.txt")
if(versionFile.canRead()) {
String versionNumber = new File("src/main/java/version.txt").text
def (major, minor, patch) = versionNumber.tokenize('.')
println major + "|" + minor + "|" + patch
def temp = major.toInteger() + 1
versionNumber = "${temp}.${minor}.${patch}"
println versionNumber
}
else {
throw new GradleException("Can not read file.")
}
That’s what I have so far but I haven’t had any luck putting the versionNumber back in.
Edit:So I also found the <<
so for example just after "println versionNumber"
putting versionFile << versionNumber will append the file but I need something which will OVERWRITE the file.