Search code examples
gradlegroovyversioning

How does the Gradle wrapper determine which Groovy version it's using?


This question doesn't mention the wrapper.

OS is Linux Mint 18.3.

So for this project I get the following from the wrapper:

mike@M17A ~/software projects/eclipse-workspace/TM_Engine_Exp $  ./gradlew -version

------------------------------------------------------------
Gradle 5.4.1
------------------------------------------------------------

Build time:   2019-04-26 08:14:42 UTC
Revision:     261d171646b36a6a28d5a19a69676cd098a4c19d

Kotlin:       1.3.21
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.4 (Ubuntu 11.0.4+11-post-Ubuntu-116.04.1)
OS:           Linux 4.4.0-53-generic amd64

From the OS I get the following (NB I know this is irrelevant!):

mike@M17A ~ $  groovy -version
WARNING: An illegal reflective access operation has occurred
...
Groovy Version: 2.5.8 JVM: 11.0.4 Vendor: Ubuntu OS: Linux

(NB the warning here occurs if you use a JDK > 8: there's nothing you can do about it currently).

And I get the following for the system's Gradle version (again irrelevant):

mike@M17A ~ $  gradle -version
WARNING: An illegal reflective access operation has occurred
...
------------------------------------------------------------
Gradle 4.8.1
------------------------------------------------------------
...
Groovy:       2.4.12
...

But my build.gradle contains the following dependency currently:

apply plugin: 'groovy'
...
dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.5.7'
    ...

My environment variable is:

GROOVY_HOME=/home/mike/.sdkman/candidates/groovy/current

I'm not sure how this came to be set. The files there are almost certainly configured to use 2.5.8, as far as I can work out.

So my question is: how is the wrapper choosing to use 2.5.4 and where am I going the find these Groovy language files?

Also, presumably the version in the dependency section of build.gradle applies only to my testing and building files (i.e. written by me in Groovy), and has nothing to do with Gradle's own build actions and other tasks?

NB I'm tempted to uninstall my system Gradle and my system Groovy, since they just confuse the issue, and just rely on using the wrapper. Is this a sensible idea?


Solution

  • Gradle comes bundled with Groovy and does not look at what other versions you have installed on your system. This is why you are seeing different Groovy versions across different Gradle versions. You cannot change this version as it is part of Gradle and likely won't work with any other versions. If you are curious, you can look in the "lib" folder in your Gradle distribution to see all third-party libraries to Gradle, including Groovy - just don't go fiddling around with them.

    As you mention, having declared a compile dependency to Groovy in your build script makes that particular version used when compiling. This is generally the only thing you should care about. (By the way, compile is deprecated, and you should use implementation.)

    I am not sure what your goal is, but I would highly recommend only using the Gradle wrapper scripts, which means you can uninstall the system installation of Gradle if you like. You can ignore the Groovy version on your system (or uninstall it if you are not using it elsewhere).