@vk I’m not an authority on Gradle by any means, but allow me to answer your seemingly rhetorical questions to give you some perspective.
You don’t. Feel free to install Gradle globally on your machine instead. It’s just much better to use the wrapper so that everyone running your project actually uses the same Gradle version as you.
As written in the first Google result: “The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary”. So basically when you set it up, people can simply clone your project and run ./gradlew build
. They don’t need to know which version of the tooling to install.
This is so that only one person has to set it up, instead of every contributor. So again, you don’t need the wrapper, but if you don’t have it then you will need to install Gradle itself in the correct version on your machine, and you might not even need the same version in every project, so that’s additional overhead that you would need to deal with.
They are not. Also, you seem to be confusing the Gradle wrapper and Gradle itself. The wrapper is just a little script (+ a jar) that ensures you’re running the version of Gradle that you want. These versions of Gradle are downloaded into the ~/.gradle/wrapper/dists
folder on your machine, which is common to all projects.
The project’s .gradle
directory mostly holds project-specific Gradle caches. What’s inside shouldn’t really matter to you. But if we want to dig, I believe the versioned folders that you see inside it simply contain pieces of the build cache or config cache produced by the corresponding Gradle version. They are probably separated for compatibility reasons (so an old version of Gradle doesn’t try to use the build cache produced by a more recent version and vice-versa).
When you change the version in gradle-wrapper.properties
, you don’t update the version of the wrapper itself, you actually tell the wrapper which version of Gradle to use (or download if not present).
Upgrading the Gradle version is definitely related to the contents of your build files: Gradle is the build tool that reads those files. Like every tool, it evolves and so does the build script’s APIs and DSLs. In a very old version of Gradle, some new concepts didn’t exist; in more recent versions, some old concepts may disappear. How would you expect the configuration format to become better over time without this?
Upgrading the wrapper itself is done by running ./gradlew wrapper
(with optional parameters). That will update the scripts and the jar of the wrapper so they match either the version of Gradle that you’re running, or the version you specified as an argument. This is what actually updates the wrapper itself, and it shouldn’t impact your build in any significant way.
That might be a bug, but also using -x test
is usually a bad idea. Applying plugins to your build configures a lot of things for you, and in particular a task graph. Compiling the files is necessary in order to execute the tests for instance, so the task that runs tests depends on the task that compiles. Excluding arbitrary tasks using -x
is a bad idea because it can break the build by removing a required dependency. Instead, use the task that does what you want to do. If you just want to build your artifacts, use assemble
instead of build
(because the latter will also run the tests).