Getting hold of version of localGroovy()


(Schalk Cronjé) #1

Is there an easy way of knowing the local version of Groovy?

I know it can be done by this UGLY hack.

groovyVer = (projects.dependencies.localGroovy().resolve(false)[0] =~ /.+groovy-all-([\p{Digit}\.]+)\.jar/)[0][1]

but I would hope for something better.


(Cédric Champeau) #2

I may be missing something, but

groovyVer = GroovySystem.version

should be enough.


(René Groeschke) #3

The groovy library ships with a properties file named “/groovy-release-info.properties”. I’d with reading out this resource for the “ImplementationVersion”. I wrote my answer before @CedricChampeau answered. His solution seems the easiest way of doing it :smile:

cheers,
René


(Schalk Cronjé) #4

Oh duh! I never thought of asking Groovy itself.


(Schalk Cronjé) #5

Now I just need a shorter version of one of these two

GroovySystem.version.split(/\./)[0..1].join('.')
GroovySystem.version.replaceAll(/\.\d+$/,'')

Only interested in major + minor


(Basil Peace) #6

The second one doesn’t work on RC versions


(Schalk Cronjé) #7

The one I normally use nowadays is:

GroovySystem.version.replaceAll(/\.\d+$/,'')

I just tried it on 4.3-rc-3 and it works. I tested it with

task foo {
  doLast {
    println "Groovy long: ${GroovySystem.version}"
    println "Groovy short: ${GroovySystem.version.replaceAll(/\.\d+$/,'')}"
  }
}

which produced the following output:

$ gradle -u foo

> Task :foo 
Groovy long: 2.4.12
Groovy short: 2.4

(Basil Peace) #8

I mean -rc is in Groovy version, not Gradle. Or any other semver prerelease or build metadata label.
Try it with the latest pre-release Groovy version 2.6.0-beta-1.


(Schalk Cronjé) #9

Replacing \d+ with \d+(-(beta|rc)-.+)? should work.


(Basil Peace) #10

Why not just start from the beginning?
/^(\d+\.\d+)/