nem*_*emo 5 gradle build.gradle
我有一个 gradle 构建脚本,其中使用“Zip”任务直接从源目录生成 zip 存档。
\n\n除了将源目录结构内的所有文件复制到 zip 存档中之外,我还在寻找一种方法来包含不在源目录中的动态生成的文件。
\n\n你们知道我该怎么做吗?
\n\n这是我想要做的伪代码:
\n\ntask('archive', type: Zip) {\n ...\n from 'source'\n newFile('dynamically-generated.txt', 'dynamic file content')\n}\nRun Code Online (Sandbox Code Playgroud)\n\n以下是源结构和目标结构:
\n\n[i71178@bddev01-shell01 ~]$ tree source/\nsource/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 file1.txt\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 file2.txt\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 file3.txt\n\n0 directories, 3 files\n[i71178@bddev01-shell01 ~]$ unzip -l destination.zip\nArchive: destination.zip\n Length Date Time Name\n\n--------- ---------- ----- ----\n 0 02-26-2016 16:56 source/\n 0 02-26-2016 16:56 source/file2.txt\n 0 02-26-2016 16:56 source/dynamically-generated.txt\n 0 02-26-2016 16:56 source/file1.txt\n 0 02-26-2016 16:56 source/file3.txt\n--------- -------\n 0 5 files\nRun Code Online (Sandbox Code Playgroud)\n
这就是我最终所做的:
subprojects {
apply plugin: 'myPlugin'
//The 'build' task is set up by the plugin
build {
//Customization to keep consistent with artifacts being currently generated.
doFirst {
new File(getTemporaryDir(), 'artifact-fullname.txt').text = "${project.name}-${project.version}\n"
}
archiveName = "${project.name}.${project.build.extension}"
from getTemporaryDir()
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢!
| 归档时间: |
|
| 查看次数: |
2133 次 |
| 最近记录: |