我在资源领域(SVN版本)。 我怎样才能获得SVN版本通过使用摇篮我场,那不这样做,用我的双手?
Answer 1:
您可以修改下面的解决方案, 解释在这里 ,能打印出当前SVN版本。
// File: build.gradle
task svninfo << {
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svn'
args = ['info']
standardOutput = os
}
def outputAsString = os.toString()
def matchLastChangedRev = outputAsString =~ /Last Changed Rev: (\d+)/
println "Latest Changed Revision #: ${matchLastChangedRev[0][1]}"
}
}
// Example output for svn info:
// Path: .
// URL: http://svn.host/svn/project
// Repository Root: http://svn.host/svn/
// Repository UUID: 9de3ae54-a9c2-4644-a1a1-838cb992bc8e
// Revision: 33
// Node Kind: directory
// Schedule: normal
// Last Changed Author: mrhaki
// Last Changed Rev: 33
// Last Changed Date: 2010-09-03 14:25:41 +0200 (Fri, 03 Sep 2010)
Answer 2:
尝试这个
task svnversion {
description 'Get SVN revision number.'
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svnversion'
standardOutput = os
}
ext.revid = os.toString()
}
}
你可以用它进行测试
task printsvn(description: 'Demonstrate calling svnversion task.') {
println 'Implementation-Build #' + svnversion.revid
}
结果
$ gradle这个printsvn
:printsvn
实施 - 建造#3071
BUILD SUCCESSFUL
总时间:0.776秒
文章来源: How to get SVN revision in Gradle for Android?