是否有一种简单的方法可以在gradle任务中写入mercurial版本(或类似的外部命令):
我还不熟悉/熟悉,但我目前的努力看起来像这样:
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()
}
}
答案 0 :(得分:13)
此构建脚本存在两个问题:
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()
}
}
答案 1 :(得分:1)
这里我有一些不同的方法,它使用javahg来获得修订。并添加任务" writeRevisionToFile"
我在我的博客Gradle - Get Hg Mercurial revision上写了一篇简短的帖子。
enum CalendarEventError: ErrorType {
case UnAuthorized
case AccessDenied
case Failed
}
func insertEventToDefaultCalendar(event :EKEvent) throws {
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(.Event) {
case .Authorized:
do {
try insertEvent(eventStore, event: event)
} catch {
throw CalendarEventError.Failed
}
case .Denied:
throw CalendarEventError.AccessDenied
case .NotDetermined:
eventStore.requestAccessToEntityType(EKEntityType.Event, completion: { (granted, error) -> Void in
if granted {
//insertEvent(eventStore)
} else {
//throw CalendarEventError.AccessDenied
}
})
default:
}
}