Skip to content

Instantly share code, notes, and snippets.

@thombergs
Last active October 21, 2020 21:51
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thombergs/9279728 to your computer and use it in GitHub Desktop.
Save thombergs/9279728 to your computer and use it in GitHub Desktop.
Accessing the SVN revision number in a Gradle script
import org.tmatesoft.svn.core.wc.*
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath group: 'org.tmatesoft.svnkit', name: 'svnkit', version: '1.7.11'
}
}
def getSvnRevision(){
ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
SVNClientManager clientManager = SVNClientManager.newInstance(options);
SVNStatusClient statusClient = clientManager.getStatusClient();
SVNStatus status = statusClient.doStatus(projectDir, false);
SVNRevision revision = status.getRevision();
return revision.getNumber();
}
allprojects {
version = '1.2.3.' + getSvnRevision()
}
@SngsuLee
Copy link

Good tip, thanks.
You should change svnkit version to recent '1.8.11' to avoid 'Client is too old' exception.

@NotCompatible
Copy link

@SNGsuli Second that.

@vehovsky
Copy link

This is great! Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment