Why should the Gradle Wrapper be committed to VCS?

后端 未结 6 1827
甜味超标
甜味超标 2021-01-29 23:49

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

The scripts generated by this

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 00:12

    What is the "project"?

    Maybe there is a technical definition of this idiom that excludes build scripts. But if we accept this definition, then we must say your "project" is not all the things that you need to versioned!

    But if we say "your project" is everything you have done. Then we can say you must include it and only it into VCS.

    This is very theoretical and maybe not practical in case of our development works. So we change it to "your project is every file (or folder) you need to editing them directly".

    "directly" means "not indirectly" and "indirectly" means by editing another file and then an effect will be reflected into this file.

    So we reach the same that OP said (and is said here):

    I think Generated files should not be in the VCS.

    Yes. Because you haven't created them. So they are not part of "your project" according to the second definition.


    What is the result about these files:

    • build.gradle: Yes. We need to edit it. Our works should be versioned.

      Note: There is no difference where you edit it. Whether in your text editor environment or in Project Structure GUI environment. Anyway you doing it directly!

    • gradle-wrapper.properties: Yes. We need to at least determine Gradle version in this file.

    • gradle-wrapper.jar and gradlew[.bat]: I haven't created or edited them in any of my development works, till this moment! So the answer is "No". If you have done so, the answer is "Yes" about you at that work (and about the same file you edited).


    The important note about the latest case is the user who clones your repo, needs to execute this command on repo's to auto-generate wrapper files:

    > gradle wrapper --gradle-version=$v --distribution-type=$distType
    

    $v and $distType are determined from gradle-wrapper.properties:

    distributionUrl=https\://services.gradle.org/distributions/gradle-{$v}-{$distType}.zip
    

    See https://gradle.org/install/ for more information.

    gradle executable is bin/gradle[.bat] in local distribution. It's not required that local distribution be same as that determined in the repo. After wrapper files created then gradlew[.bat] can download determined Gradle distribution automatically (if not exists locally). Then he/she probably must regenerate wrapper files using new gradle executable (in downloaded distribution) using above instructions.


    Note: In the above instructions, supposed the user has at least one Gradle distribution locally (e.g. ~/.gradle/wrapper/dists/gradle-4.10-bin/bg6py687nqv2mbe6e1hdtk57h/gradle-4.10). It covers almost all real cases. But what happens if the user hasn't any distribution already?

    He/She can download it manually using the URL in .properties file. But if he/she doesn't locate it in the path that the wrapper expected, the wrapper will download it again! The expected path is completely predictable but is out of the subject (see here for the most complex part).

    There are also some easier (but dirty) ways. For example, he/she can copy wrapper files (except .properties file) from any other local/remote repository to his/her repository and then run gradlew on his/her repository. It will automatically download the suitable distribution.

提交回复
热议问题