Is it possible to do simple string replacement in gradle where placeholders / tokens can not be used.
For example: given temp.txt
replace all occurences of xxx
with yyy
.
Is it possible to do simple string replacement in gradle where placeholders / tokens can not be used.
For example: given temp.txt
replace all occurences of xxx
with yyy
.
I assume you are talking about resource processing. In that case, you can use the free-form filter
method:
processResources {
filter { String line -> line.replace(...) }
}
Read the text in:
String contents = new File( 'whatever.txt' ).getText( 'UTF-8' )
Replace the text
contents = contents.replaceAll( 'xxx', 'yyy' )
Write the text out again
new File( 'replaced.txt' ).write( contents, 'UTF-8' )
You should be able to wrap them into a task and call the task as normal
To replace in-place:
ant.replaceregexp(file: fout, flags: "g",
match: 'schemaLocation="[^"]+/', replace: 'schemaLocation="', encoding: 'UTF-8')
Reference for syntax: