1

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.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
kiltek
  • 3,183
  • 6
  • 47
  • 70

2 Answers2

3

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.

Shashank Agrawal
  • 25,161
  • 11
  • 89
  • 121
  • Although this works when running the Grails application locally with `bootRun`, it doesnt work when creating the war file and deploying it to a server. The latter returns always `null`. Do you have an idea how to make this work for a deployed war file? – kiltek Jul 28 '16 at 08:31
  • Have you tried printing the `System.properties` in the build ? – Shashank Agrawal Jul 28 '16 at 09:49
1

Another way to achieve this (in addition to the solution provided by Shashank Agrawal) is relying on grailsApplication bean, with the following code:

grailsApplication.config.getProperty('info.app.version')

I tested this with Grails 3.1.9 and 3.2.7.