按照约定将文件复制到Tar时,将fileMode设置为* .sh [英] Set fileMode for *.sh When Copying Files To Tar By Convention
问题描述
如果我有这样的gradle文件
If I have a gradle file like this
apply plugin: 'distribution'
version = '1.2'
distributions {
custom {}
}
按照惯例,"src/custom/dist"目录中的所有文件将自动包含在发行版中. https://docs.gradle.org/current/userguide/distribution_plugin.html
By convention, all of the files in the "src/custom/dist" directory will automatically be included in the distribution. https://docs.gradle.org/current/userguide/distribution_plugin.html
如果我要在其中一些文件上设置fileMode怎么办?
What if I want to set the fileMode on some of these files?
如果我只指定fileMode,它什么也不会做.
If I just specify the fileMode it doesn't do anything.
into("") {
from "src/custom/scripts"
fileMode 0755
}
如果我将脚本放在另一个目录中并显式复制它们(而不是按常规复制它们,则下面的代码将起作用.
If I put the scripts in another dir and explicitly copy them (rather than them being copied by convention, the code below works.
distributions {
custom {
baseName = 'myApp'
contents {
into("") {
from "src/external/scripts"
fileMode 0755
}
}
}
我想知道是否可以将文件保留在常规位置,但可以更改某些文件的属性.
I am wondering if it is possible to have the files in the conventional place but change the attributes on some of the files.
推荐答案
在@RaGe链接之后,我想到了这一点:
Following @RaGe link I came up with this:
distributions {
custom {
baseName = 'myApp'
contents {
//Other stuff
eachFile { file ->
if(file.getName().endsWith(".sh")) {
file.setMode(0755)
}
}
}
这篇关于按照约定将文件复制到Tar时,将fileMode设置为* .sh的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!