[英]How to compress a single file in Gradle?
How to compress a single file inside a Copy
task without having extra headache with creating and compressing temporary files manually? 如何在“ Copy
任务中压缩单个文件,而又不必手动创建和压缩临时文件而感到头疼?
For example, when you build a deb
package, you should compress some files with gzip
: 例如,当构建一个deb
软件包时,应使用gzip
压缩一些文件:
task buildDeb(type: Deb, dependsOn: ['jar']) {
// ...
from (file('packaging/deb-package/manpage')) {
into '/usr/share/man/man1'
//rename(/.*/, deploymentName + '.1.gz')
rename(/.*/, deploymentName + '.1')
filteringCharset = 'UTF-8'
filter(ReplaceTokens, tokens: [
'TITLE': appTitle,
// ...
])
// XXX
//compressItWithGzip();
}
// ...
}
The built-in ant
tools support only text filtering via the Reader
interface. 内置的ant
工具仅支持通过Reader
界面进行文本过滤。 So, how to do something like compressing (or, in general, any binary manipulation)? 那么,如何做类似压缩的操作(或者,一般而言,任何二进制操作)?
You can try: 你可以试试:
ant.gzip(src: <source>, zipfile: <target>)
in you task, catch the docs . 在您的任务中,赶上docs 。
Also, maybe instead of putting too much logic in a single task, define a set of tasks (one would be responsible for this gzipping) and tie them with dependencies. 另外,也许不要在单个任务中放置太多逻辑,而是定义一组任务(一个将负责此gzip压缩)并将它们与依赖项联系起来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.