I made it work using mostly code from this comment:
https://stackoverflow.com/a/25872141/5132130
I added the following to the top of the gradle file:
def getSvnRevisionNr() {
description 'Get SVN revision number.'
new ByteArrayOutputStream().withStream { os ->
def result = exec {
executable = 'svnversion'
standardOutput = os
}
return '"' + os.toString().trim() + '"'
}
}
The changes I made in relation to the comment I linked:
- I wanted a result that could be used for the String, so I needed to add the '"' parts and the trim()
- I returned it as is, without storing in variable inside method
And in my buildTypes:
buildTypes {
debug {
minifyEnabled false
buildConfigField("String", "SVN_REVISION", getSvnRevisionNr())
}
release {
minifyEnabled false
buildConfigField("String", "SVN_REVISION", getSvnRevisionNr())
}
}
Then in my code i can access it using:
BuildConfig.SVN_REVISION