3

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?

2 Answers 2

7

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() 
2
  • This works great, except behind git svn. I have to pull off of my build server to get the app version, but this is the way to go. Mar 11, 2011 at 17:39
  • This prints the SVN url, not version as suggested. I wanted the revision number so I used def version = svninfo.revision.
    – nickdos
    May 16, 2014 at 5:13
0

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
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.