I have some files that need token replacement .. instead of the default single @, they use double @'s ... So I need stuff like: @@replaceme@@ .. replaced.
Ant's ReplaceTokens filter allows you to set it using BeginToken / EndToken .. Though I'm not sure how to configure it in my example:
copy{
into something
from somethingelse
filter(ReplaceTokens, tokens: [])
}
How can I change the above code to replace correctly work with double @@ tokens instead of single ones?
It's easy to change the delimiters - just add named parameters beginToken
and endToken
to the filter
method call. However, Ant's ReplaceTokens
only support single-character delimiters. A quick web search didn't turn up an Ant FilterReader
that supports arbitrary multi-character delimiters out of the box. An alternative is to code this yourself, either by implementing FilterReader
or by using the free-form filter method.
I was in a similar (not exact) situation. Had to process test property resources which were in maven format. i.e '${}' format.
When I moved onto gradle, processTestResources task did not replace the values in ${}. This is because of the same reason that it uses '@' single char delimited. I found a hack to achieve what I wanted.
configure(tasks.processTestResources) {
include '**/*.properties'
filter(ReplaceTokens,
tokens: ['$':'={'], beginToken : '=', endToken : '{')
filter(ReplaceTokens,
tokens: [project.properties], beginToken : '{', endToken : '}')
}
The other answers seem to be old and report that you can't use multi-character token delimiters. But I have found that not to be the case anymore with Gradle 2.14.1
copy{
into something
from somethingelse
filter(ReplaceTokens, tokens: [map], beginToken : '@@', endToken : '@@')
// or, maven prop stle:
// filter(ReplaceTokens, tokens: [map], beginToken : '${', endToken : '}')
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With