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.
I may be missing something, but
groovyVer = GroovySystem.version
should be enough.
1 Like
Rene
(René Groeschke)
November 4, 2015, 2:35pm
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
cheers,
René
Oh duh! I never thought of asking Groovy itself.
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
grv87
(Basil Peace)
October 24, 2017, 9:38pm
6
The second one doesn’t work on RC versions
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
grv87
(Basil Peace)
November 1, 2017, 7:33pm
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
.
Replacing \d+
with \d+(-(beta|rc)-.+)?
should work.
grv87
(Basil Peace)
November 6, 2017, 9:37pm
10
Why not just start from the beginning?
/^(\d+\.\d+)/