Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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, gradle 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?

like image 431
ataylor Avatar asked Sep 01 '11 20:09

ataylor


1 Answers

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.

like image 89
ataylor Avatar answered Sep 18 '22 00:09

ataylor