I'm trying to add the svn revision to my app.version
without requiring ant or some other similar external tool. It looks like I might be able to hook into _Events.groovy
to this, but the documentation is relatively sparse.
Anyone know how to do this?
This link from the Grails nabble mailing list has the solution you're looking for. Also putting the code here for completeness:
In scripts/_Events.groovy
eventWarStart = { type ->
println "******************* eventWarStart *****************"
try {
// initialise SVNKit
DAVRepositoryFactory.setup();
SVNRepositoryFactoryImpl.setup();
FSRepositoryFactory.setup();
SVNClientManager clientManager = SVNClientManager.newInstance();
println "clientManager = " + clientManager.toString();
SVNWCClient wcClient = clientManager.getWCClient();
println "wcClient = " + wcClient.toString();
// the svnkit equivalent of "svn info"
File baseFile = new File(basedir);
println "baseFile = " + baseFile.toString();
SVNInfo svninfo = wcClient.doInfo(baseFile, SVNRevision.WORKING);
println "svninfo = " + svninfo.toString();
def version = svninfo.getURL();
println "Setting Version to: ${version}"
metadata.'app.version' = "${version}".toString()
metadata.persist()
}
catch (SVNException ex) {
//something went wrong
println "**************** SVN exception **************"
println ex.getMessage();
}
} // End eventWarStart()
Grails 3.x, in build.gradle, add svn revision to app version:
version "1.0.${getSvnRevision()}"
def getSvnRevision() {
def proc = "svnversion".execute()
return proc.in.text
}