Search code examples
grailsjenkinsgradlebuild.gradlegrails3

Grails 3 set-version replacement


On our Grails 2 projects we used the set-version command line option. I do not see that command available in Grails 3. I do see the version property in the gradle.build file. Did that replace the app.version from the application.properties? I build our projects using Jenkins and SVN repository. What is the best way to handle setting the version parameter for Grails 3 to the SVN revision number. Below is a section of the build.gradle file, that includes the version property, which is generated when creating a Grail 3 application.

buildscript {
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.8.2"
        classpath "org.grails.plugins:hibernate5:6.0.0.M2"
    }
}

version "0.1"
group "appName"

apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"

In grails 2 the property was called app.version (from the application.properties file) and could be referenced in gsp using the following:

Revision: <g:meta name="app.version"/>

Solution

  • After some trail and error using Grails 3.2.0.M2 I was successful using the Gradle plugin to Jenkins. I was able to use the Environment variable SVN_REPOSITORY so I edited the build.gradle to:

    version System.getenv('SVN_REVISION')
    

    Also I noticed in the generated index.gsp that the property name for the version value using the g:meta tag library has changed. The name has changed to info.app.version so here is an example how to use the value now:

    <g:meta name="info.app.version"/>
    

    Also for the grails version the name has also changed:

    <g:meta name="info.app.grailsVersion"/>