How to make expand not remove escape chars?


(Blaine Mucklow) #1

I am trying to replace a variable in a source file…yes I know…very dangerous, but I don’t see any other real option. So I am copying my source set to a new location while using expand(project:project) to replace variable like ${project.version}. This works, however it also erroneously removes some escape chars in other files. For example I have “\|” that gets changed to “|”. So basically one of the 's is removed causing the build to fail because the it is not escaped correctly.

Why is expand removing these “” chars? And how can I tell it not to.

Here is the pertinent part of the build.gradle file: https://gist.github.com/bmucklow/3e17536345b78752a062

Thanks


(Peter Niederwieser) #2

‘Copy.expand()’ is based on Groovy’s ‘SimpleTemplateEngine’, and has several known limitations. I can’t tell for sure if you are hitting one of them, but in my experience, ‘Copy.filter()’ together with an Ant ‘FilterReader’ is often a better choice. Have a look at the Filtering files example in the Gradle User Guide.


(Blaine Mucklow) #3

Peter, Thanks for the quick response. I played with Filter temporarily but it gave different errors. Mainly that any file that had filter changes applied could not be copied to the destination directory. Threw some error. I wound up using the expand but limited to the one source file i needed it to replace a variable and then adding that copied file to the main source set/removing the unfiltered file from the sourceset. A hacky workaround.