有没有一种简单的方法可以在gradle任务中写入文件版本(或类似的外部命令):
我尚未精通groovy / gradle,但是我目前的工作是这样的:
task versionInfo(type:Exec){
commandLine 'hg id -i -b -t'
ext.versionfile = new File('bin/$baseName-buildinfo.properties')
doLast {
versionfile.text = 'build.revision=' + standardOutput.toString()
}
}
最佳答案
此构建脚本有两个问题:
hg id -i -b t
的二进制文件,而不是带有hg
,id
,-i
和-b
t
ByteOutputStream
以便以后阅读试试这个:
task versionInfo(type:Exec){
commandLine 'hg id -i -b -t'.split()
ext.versionfile = new File('bin/$baseName-buildinfo.properties')
standardOutput = new ByteArrayOutputStream()
doLast {
versionfile.text = 'build.revision=' + standardOutput.toString()
}
}