我有一个要转换为gradle的ant项目。在ant项目中,是这样的:

<copy todir="dest_dir">
  <fileset>
     ...
  </fileset>
  <filterchain>
    <expandproperties/>
  </filterchain>
</copy>

过滤器链扩展了${property}之类的属性,但忽略不带花括号的美元符号。我正在尝试在gradle中复制此行为。

如果我按以下方式expand,则gradle会将文件扩展为常规模板,该模板尝试使用花括号扩展美元符号。
copy {
   from 'source_dir'
   into 'dest_dir'
   expand(project.properties)
}

如果我使用ant filter过滤器类来ExpandProperties,则会收到NullPointerException。有没有简单的方法可以做到这一点,我错过了吗?

最佳答案

好的,我知道了。 ExpandProperties过滤器需要使用Ant项目设置其项目属性。这是我将其配置为工作的方式:

copy {
    from 'source_dir'
    to 'dest_dir'
    filter(org.apache.tools.ant.filters.ExpandProperties, project: ant.antProject)
}

这将扩展${property}之类的属性,使其与Ant完全相同,而不会在没有大括号的情况下绊倒美元符号。

关于ant - 使用gradle扩展属性时如何获得 Ant 行为?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7276368/

10-16 14:03