渐变脚本
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>
我得到了复制文件的顶部,但在复制时我一直在过滤文件。有人能帮我吗?
您需要在CopySpec
中添加对filter
的调用。
基于原始Ant脚本,您需要:
import 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])
}
这使用ReplaceTokens将Telescope.java
中的文字文本Tel-IntVer-Tel
替换为interfaceVersion
的值,因为它是从src/com/comcast/telescope
复制到dist/com/comcast/telescope
的
请注意,在我的示例中,您需要将interfaceVersion
属性设置在某个位置,如gradle.properties
或ext
块中。最后,我认为include
是不必要的,因为只有一个文件被复制,产生:
import org.apache.tools.ant.filters.ReplaceTokens
copy {
from 'src/com/comcast/telescope/Telescope.java'
into 'dist/com/comcast/telescope'
filter(ReplaceTokens, beginToken:'Tel-', endToken:'-Tel', tokens: [IntVer: interfaceVersion])
}