Why should the Gradle Wrapper be committed to VCS?

gradle version command
should i commit gradle folder
gradle wrapper makes the execution of the build independent of the installed gradle version.
upgrade gradle wrapper to 26 version and 're import the project
where does gradle wrapper download gradle
gradle wrapper dependencies
gradle set version
gradle-wrapper proxy

From Gradle's documentation: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.wrapper.Wrapper.html

The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. The scripts delegates to this JAR.

From: What should NOT be under source control?

I think Generated files should not be in the VCS.

When are gradlew and gradle/gradle-wrapper.jar needed?

Why not store a gradle version in the build.gradle file?

Because the whole point of the gradle wrapper is to be able, without having ever installed gradle, and without even knowing how it works, where to download it from, which version, to clone the project from the VCS, to execute the gradlew script it contains, and to build the project without any additional step.

If all you had was a gradle version number in a build.gradle file, you would need a README explaining everyone that gradle version X must be downloaded from URL Y and installed, and you would have to do it every time the version is incremented.

The Gradle Wrapper, I don't like having such files to VCS. The Wrapper is a script that invokes a declared version of Gradle, downloading it beforehand if necessary. I see projects having commits where the gradle-wrapper.properties gets  The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. The scripts delegates to this JAR.

Because the whole point of the gradle wrapper is to be able, without having ever installed gradle

Same argument goes for the JDK, do you want to commit that also? Do you also commit all your dependencie libraries?

The dependencies should be upgraded continuously as new versions are released. To get security and other bug fixes. And because if you get to far behind it can be a very time consuming task to get up to date again.

If the gradle wrapper is incremented for every new release, and it is committed, the repo will grow very large. The problem is obvious when working with distributed VCS where a clone will download all versions of everything.

, and without even knowing how it works

Create a build script that downloads the wrapper and uses it to build. Everyone does not need to know how the script works, they need to agree that the project is build by executing it.

, where to download it from, which version

task wrapper(type: Wrapper) {
 gradleVersion = 'X.X' 
}

And then

gradle wrapper

To download the correct version.

, to clone the project from the VCS, to execute the gradlew script it contains, and to build the project without any additional step.

Solved by the steps above. Downloading the gradle wrapper is not different from downloading any other dependencies. The script could be smart enaugh to check for any current gradle wrapper and only download it if there is a new version.

If the developer has never used Gradle before and maybe not knowing the project is build with Gradle. Then its more obvious to run a "build.sh" compared to running "gradlew build".

If all you had was a gradle version number in a build.gradle file, you would need a README explaining everyone that gradle version X must be downloaded from URL Y an installed,

No, you would not need a README. You could have one, but we are developers and we should automate as much as possible. Creating a script is better.

and you would have to do it every time the version is incremented.

If the developers agree that the correct process is to:

  1. Clone repo
  2. Run build script

Then there upgrading to latest gradle wrapper is no problem. If the version is incremented since last run, the script could download the new version.

Adding gradle wrapper files to gitignore - Help/Discuss, This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. As mentioned by @alijandro, if the gradle-wrapper.jar in your two projects are not using the same hash policy, or not the same as the Android Studio app, it will cause the problem you saw. To get rid of this, just copy the gradle-wrapper.jar from Android Studio app directory to your project and you're all set.

Added missing Gradle wrapper jar, and updated gitignore · Issue , due to *.jar being ignored by Git, the Gradle wrapper jar file is missing. file and properties file which should also be committed to your VCS. gradle <task> When I should have been running:./gradlew <task> Presumably because running the global gradle tries to create a local wrapper -- and one already existed.

Use the Gradle Wrapper and Stop Wasting Valuable Time, If Gradle ever needs to be upgraded, all you need to do is change the version used in the Gradle Wrapper and commit this code to your SCM. Any installed Gradle distribution is ignored when using the wrapper scripts. The scripts generated by this task are intended to be committed to your version control system. This task also generates a small gradle-wrapper.jar bootstrap JAR file and properties file which should also be committed to your VCS. The scripts delegates to this JAR.

According to Gradle docs, adding gradle-wrapper.jar to VCS is expected as making Gradle Wrapper available to developers is part of the Gradle approach:

To make the Wrapper files available to other developers and execution environments you’ll need to check them into version control. All Wrapper files including the JAR file are very small in size. Adding the JAR file to version control is expected. Some organizations do not allow projects to submit binary files to version control. At the moment there are no alternative options to the approach.

Understanding the Gradle Wrapper - Bryan Herbst, This is great because using the Gradle Wrapper means that developers You should make sure all these are committed to version control. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information. Why should the Gradle Wrapper be committed to VCS

How to use Gradle Wrapper, In this tutorial, we will show you how to create Gradle wrapper for your project and how to use it. What is Gradle wrapper? The Gradle wrapper  The better and recommended option is to run the wrappertask and provide the target Gradle version as described in Adding the Gradle Wrapper. Using the wrappertask ensures that any optimizations made to the Wrapper shell script or batch file with that specific Gradle version are applied to the project.

Manage files under version control - Help, If you have enabled VCS integration for your project, IntelliJ IDEA suggests to add is under version control, it still exists in the repository until you've committed  Gradle caches artifacts in USER_HOME/.gradle folder. The compiled scripts are usually in the .gradle folder in your project folder. If you can't find the cache, maybe it's because you have not cached any artifacts yet. You can always see where Gradle has cached artifacts with a simple script:

The Gradle build system- Tutorial, It is a gradle-${version}-all.zip, where ${version} is a placeholder for the file to the root directory of your project and commit it to your version control system. the task gradle vogellaCompany can also be called with the gradle vC command. You could put everything else in the .gitignore file. All your app changes lies mostly in these files and folders. The rest you see in a basic project are gradle build files or Android Studio configuration files. If you are using Android Studio, you can use "Import project" to successfully build the project.

Comments
  • What might be an interesting side discussion, given the answers below, is the usefulness of these files if you're using some form of continuous integration tool. Which ones will check for grade-wrapper and use it if it's there?
  • That's stupid. gradle-wrapper.jar shouldn't be needed on the VCS. Gradle should be able to download any version once you installed a first one, if needed. The toolchain has nothing to do on a VCS… I understand your answer is right, and it's Gradle's design. But this design is absurd.
  • The point is to be able to download gradle without having installed gradle before. What's the problem in having a 50KB-large file in the VCS?
  • The problem is that it's not a part of the project. It's a tool you use to build the project. You won't store the JDK in VCS, would you? Nor GCC for a C application? So why would you store a Gradle part? If a developer is unable to read and install Gradle himself, that's another problem.
  • The problem is also that you can't remember, 2 years after it has been released, which version of Gradle was used to build the v1.0 version of your software, that you have to hotfix for a customer which is still using this 1.0 version and can't upgrade. The gradle wrapper solves that: you clone the 1.0 tag from the VCS, build it using gradlew, and it uses the gradle version that was used 2 years ago to build the 1.0 version.
  • I agree that the Gradle version to be used needs to be indicated somewhere in the project. But Gradle is an external tool, nothing comparable with a README or anything you listed. Gradle should be able to fetch the corresponding version itself, without having to store a jar on the VCS.
  • "The dependencies should be upgraded continuously." Yes, in a forward looking direction. No, in a backward looking direction. To reproduce an old build, you need to have specific versions of the dependencies. Gradle makes some types of projects faster and easier to deal with. It would be a mess in an organization that needed reproduction and auditing.
  • Not really sure what you mean. But if you have build.gradle in version control and in it you have: task wrapper(type: Wrapper) { gradleVersion = 'X.X' } Then gradle wrapper will download the wrapper that was used, and you can reproduce the old build.
  • Was referring to your line about the dependencies, not the gradle version. Sure, you want your libraries to have all the latest security and bug fixes but NOT when you're trying to reproduce an old build, maybe for auditing or legal purposes. You want your libraries and build process to be able to produce a binary identical output, if at all possible. As with a library dependency, there's no guarantee that a specific version would be available at the time of building... be it 2 weeks from now or 2 decades from now. So yes, it is the same as libraries and SDKs, for some projects.
  • I think the wrapper is there primarily for historic reason. In the beginning everyone is using Maven, and nobody has Gradle installed. It would be difficult to persuade co-worker to install unknown intrusive dependencies, so the wrapper helps them bootstrap. Nowadays everyone has Gradle already, and the wrapper becomes redundant.
  • Are you suggesting to execute gradle wrapper after clone on every build? This basically makes wrapper useless, because its whole point is that you do not have to install Gradle locally to build the project!
  • why would you need wrapper then? The whole idea of wrapper is that you can build project without having gradle on your system.
  • Nice solution. No binaries in git and still an ability to use gradlew. @edio you will need it to download and use a specific version of gradle.