How can I get ant behavior when expanding properties with gradle?
I have an ant project I'm converting to gradle. In the ant project, there is something like this:
<copy todir="dest_dir">
<fileset>
...
</fileset>
<filterchain>
<expandproperties/>
</filterchain>
</copy>
The filter chain expands properties like ${property}
, but ignores dollar signs without braces. I'm trying to replicate this behavior in gradle.
If I expand
as below, gra开发者_如何学Pythondle expands the files as a groovy template, which tries to expand dollar signs with braces.
copy {
from 'source_dir'
into 'dest_dir'
expand(project.properties)
}
If I filter
with the ant ExpandProperties
filter class, I get a NullPointerException. Is there an easy way to do this I've missed?
Ok, I figured this out. The ExpandProperties filter needs its project property set with the Ant project. This is how I got it configured to work:
copy {
from 'source_dir'
to 'dest_dir'
filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.antProject)
}
This expands properties like ${property}
exactly the same as Ant, without getting tripped up on dollar signs without braces.
精彩评论