How do I find out Groovy runtime version from a running app?

Groovy

Groovy Problem Overview


I need to be able to find out the version of Groovy runtime via a groovy script. How do I do it? The examples I found on the net show a way, but apparently it has been deprecated and removed in the latest version.

Groovy Solutions


Solution 1 - Groovy

This should work:

println GroovySystem.version

So long as you are on Groovy 1.6.6+

Before that, it was:

println org.codehaus.groovy.runtime.InvokerHelper.version

But that's been removed from later versions of Groovy

Solution 2 - Groovy

To improve slightly on tim_yates' answer, here's the universal code to get Groovy version:

public String getGroovyVersion() {
        try {
                return org.codehaus.groovy.runtime.InvokerHelper.version
        }
        catch (Throwable ignore) { }
        return GroovySystem.version
}

println getGroovyVersion()

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAlex KhvatovView Question on Stackoverflow
Solution 1 - Groovytim_yatesView Answer on Stackoverflow
Solution 2 - GroovyravilovView Answer on Stackoverflow