grails add svn revision to app.version

2020-06-06 02:08发布

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条回答
唯我独甜
2楼-- · 2020-06-06 02:47

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
}
查看更多
【Aperson】
3楼-- · 2020-06-06 02:54

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() 
查看更多
登录 后发表回答