grailsgradlebuild.gradlegrails-3.1

Grails access variable in build.gradle from Service class


I am sitting in front of a Grails 3.1.4 Application. The build.gradle file looks like this:

buildscript {
    ...
}


version "01.01.12.99"

...

ext {
    ...
}

repositories {
    ...
}

dependencyManagement {
    ...
}

dependencies {
    ...
}

From one of my Service Classes I want to access the version variable. Is this somehow built in into Grails or am I trying to do something impossible? Are there ways to load this variable from a Service class?

I searched a bit and found this, but it accesses the Grails version not the project version.


Solution

  • Well, I recently started using Grails 3. Here I got the solution:

    println System.properties.getProperty("info.app.version")
    

    And you will get "01.01.12.99". This is working on Grails 3.1.8 for me.