javagradlemultiple-versions

Gradle multiple versions OF GRADLE


For the sake of clarity: this is NOT about multiple versions of dependencies, it's about multiple versions of Gradle's own jars.

I thought this might have the answer... but there aren't any!

This is Gradle 2.14, with a Windows 10 OS.

I found that gradle was constantly building a new directory under the ".gradle\" directory for this project: alongside the legitimate "2.14\" directory it kept building a "2.2.1\" directory.

I looked under my directory where Gradle is installed: and puzzlingly I found multiple versions of Gradle's jar files: not only 2.14, but 2.13, 1.7, and yes, 2.2.1..

So I decided to manually delete the 2.2.1. jars. It stopped building the "spurious" 2.2.1 directory.

Can someone tell me how Gradle decides which version of itself it is using? I'd really like to get rid of those non-2.14 jars and find a way to prevent other versions creeping back in somehow!


Solution

  • Can someone tell me how Gradle decides which version of itself it is using ?

    This depends on how you invoke gradle.

    Method 1. A gradle command will invoke the version of gradle which is in your GRADLE_HOME path.

    Method 2. Using gradle wrapper

    A gradlew command will invoke the version of gradle which is configured in your project's gradle\wrapper\gradle-wrapper.properties file if it exists already. If its not, you can create it by gradle wrapper --gradle-version 3.3. Now when you use gradlew , it will always use gradle version 3.3.

    The use of gradle wrapper is recommended so that you can consistently reproduce the same build in different machines where the installed gradle versions might be different or even on machines where gradle is not installed, because gradlew.bat and gradlew will be used on windows and linux respectively for bootstrapping the build.

    The reason you found multiple version of gradle in your .gradle directory might be because previously you might have tried to build with those versions for gradle.