如何在复制文件时过滤gradle?如果令牌以“Tel-”开头并以“-Tel”结尾,则用V2替换令牌

时间:2016-07-29 20:19:19

标签: gradle ant

Gradle脚本

copy {
    from 'src/com/comcast/telescope/Telescope.java'
    into 'dist/com/comcast/telescope'
include '**/*.java'
 }

Ant脚本

     <copy file="${src.dir}/com/comcast/telescope/Telescope.java" toFile="${dist.dir}/com/comcast/telescope/Telescope.java">
        <filterset begintoken="Tel-" endtoken="-Tel">
            <filter token="IntVer" value="${Interface-Version}" />
        </filterset>

我得到了复制文件的顶部部分,但是在复制时我仍然坚持过滤文件。有人能帮助我吗?

1 个答案:

答案 0 :(得分:1)

您需要在try。{/ p>中添加对filter的来电

基于原始Ant脚本,您需要:

CopySpec

使用ReplaceTokensimport org.apache.tools.ant.filters.ReplaceTokens copy { from 'src/com/comcast/telescope/Telescope.java' into 'dist/com/comcast/telescope' include '**/*.java' filter(ReplaceTokens, beginToken:'Tel-', endToken:'-Tel', tokens: [IntVer: interfaceVersion]) } 中的文字Tel-IntVer-Tel替换为Telescope.java的值,因为它从interfaceVersion复制到src/com/comcast/telescope }

请注意,在我的示例中,您需要在某处设置dist/com/comcast/telescope属性,例如在interfaceVersionext block.中。最后,我认为gradle.properties是不必要的,因为只复制了一个文件,产生:

include