Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle String Replacement - no placeholders

Tags:

gradle

groovy

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.

like image 898
user568280 Avatar asked May 10 '12 11:05

user568280


1 Answers

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

like image 71
tim_yates Avatar answered Oct 01 '22 04:10

tim_yates