Grails adds svn version to app.version

I am trying to add an svn version to mine app.versionwithout requiring an ant or other similar external tool. It looks like I could connect _Events.groovyto this, but the documentation is relatively rare.

Does anyone know how to do this?

+3
source share
2 answers

This Grails nabble mailing list link has the solution you are looking for. Also add the code for completeness:

AT 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() 
+7
source

Grails 3.x, in build.gradle, add the svn version to the application version:

version "1.0.${getSvnRevision()}"

def getSvnRevision() {
    def proc = "svnversion".execute()
    return proc.in.text
}
0
source

All Articles