I'm following the answer given in Replace the string in file using groovy, but am getting an error. I just want to replace, for example
From
version=1.1.0
To
version=1.1.1
in some file. I do
String sv1 = '1.1.0'
String sv2 = '1.1.1'
def file = new File(`/some_path/someFile')
def fileText = file.replaceAll("version=$sv1", "version=$sv2")
file.write(fileText)
I get
Caught: groovy.lang.MissingMethodException: No signature of method: java.io.File.replaceAll() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl) values: [version=1.1.0, version=1.1.1]
groovy.lang.MissingMethodException: No signature of method: java.io.File.replaceAll() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl, org.codehaus.groovy.runtime.GStringImpl) values: [version=1.1.0, version=1.1.1]
at pre-push.updatePatchVersion(pre-push:154)
at pre-push.compareVersions(pre-push:188)
at pre-push.run(pre-push:219)
Are the dots (.) in the string messing it up? What's the proper syntax if so? Thanks.