如何/何时生成Gradle包装文件? [英] How/when to generate Gradle wrapper files?

查看:197
本文介绍了如何/何时生成Gradle包装文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想了解Gradle Wrapper的工作原理。在许多源代码仓库中,我看到以下结构:

  projectRoot / 
src /
build.gradle
gradle.properties
settings.gradle
gradlew
gradlew.bat
gradle /
包装器/
gradle-wrapper.jar
我的问题:


  1. 如何/何时产生 gradlew / gradlew.bat ?你是否应该在项目第一次创建时只生成一次,每次提交/推送更改时是否生成它们?它们是如何生成的?

  2. 同样的问题,但对于 gradle / wrapper / * 文件( gradle-wrapper.jar gradle-wrapper.properties )?

  3. 有时我会看到其他 *。gradle 文件在项目的 gradle 目录中。这些额外的Gradle文件是什么?它们代表什么?自定义插件?

  4. settings.gradle 中的属性与 gradle.properties


解决方案


  1. 你生成一次,再次当你想改变你在项目中使用的Gradle版本时。没有必要经常产生。 这里是文档。只需将 wrapper 任务添加到 build.gradle 文件中,并运行此任务即可获得包装结构。



    请注意,您需要安装 Gradle 才能生成包装。管理g生态系统工件的好工具是 SDKMAN!。要生成gradle包装,请将以下代码片段添加到 build.gradle 文件中:

      task wrapper(type:Wrapper){
    gradleVersion ='2.0'//需要的版本
    }

    并运行:

      gradle wrapper 

    任务。将结果文件添加到SCM(例如git),从现在起,所有开发者在使用Gradle Wrapper时都会拥有相同版本的Gradle。



    使用Gradle 2.4

    strong>(或更高),你可以设置一个包装而不需要增加一个专门的任务:

      gradle wrapper --gradle-version 2.3 

      gradle wrapper --gradle-distribution-url https:// myEnterpriseRepository:7070 / gradle / distributions / gradle-2.3-bin.zip 

    所有的细节都可以找到 here here




  2. 从Gradle 3.1 - distribution-type 选项也可以使用。这些选项是二进制的, all bin all 另外包含源代码和文档。当使用IDE时, all 也更好,所以编辑器效果更好。缺点是构建可能会持续更长的时间(需要下载更多的数据,在CI服务器上毫无意义),并且需要更多空间。


    1. 这些是Gradle Wrapper文件。您需要生成一次(针对特定版本)并添加到版本控制。如果您需要更改Gradle Wrapper的版本,请更改 build.gradle 中的版本(请参阅(1.)并重新生成文件。)


    2. 举一个详细的例子。这样的文件可能有多种用途:多模块项目,责任分离,略微修改的脚本等。

    3. code>负责项目结构(模块,名称等),而 gradle.properties 用于项目和Gradle的外部详细信息(版本,命令行参数 -XX ,属性等)。


    I am trying to understand how the Gradle Wrapper works. In many source repos, I see the following structure:

    projectRoot/
        src/
        build.gradle
        gradle.properties
        settings.gradle
        gradlew
        gradlew.bat
        gradle/
            wrapper/
                gradle-wrapper.jar
                gradle-wrapper.properties
    

    My questions:

    1. How/when does one generate gradlew/gradlew.bat? Are you supposed to generate them only one time when the project is first created, do you generate them every time you commit/push changes? And how are they generated?
    2. Same question above, but for the gradle/wrapper/* files (gradle-wrapper.jar and gradle-wrapper.properties)?
    3. Some times I see other *.gradle files inside the project's gradle directory. What are these additional Gradle files and what do they represent/do? Custom plugins?
    4. What is the difference in properties that go into settings.gradle vs what should be defined inside gradle.properties?

    解决方案

    1. You generate it once, and again when you'd like to change the version of Gradle you use in the project. There's no need to generate is so often. Here are the docs. Just add wrapper task to build.gradle file and run this task to get the wrapper structure.

      Mind that you need to have Gradle installed to generate a wrapper. Great tool for managing g-ecosystem artifacts is SDKMAN!. To generate a gradle wrapper, add the following piece of code to build.gradle file:

      task wrapper(type: Wrapper) {
         gradleVersion = '2.0' //version required
      }
      

      and run:

      gradle wrapper
      

      task. Add the resulting files to SCM (e.g. git) and from now all developers will have the same version of Gradle when using Gradle Wrapper.

      With Gradle 2.4 (or higher) you can set up a wrapper without adding a dedicated task:

      gradle wrapper --gradle-version 2.3
      

      or

      gradle wrapper --gradle-distribution-url https://myEnterpriseRepository:7070/gradle/distributions/gradle-2.3-bin.zip
      

      All the details can be found here

    From Gradle 3.1 --distribution-type option can be also used. The options are binary and all and bin. all additionally contains source code and documentation. all is also better when IDE is used, so the editor works better. Drawback is the build may last longer (need to download more data, pointless on CI server) and it will take more space.

    1. These are Gradle Wrapper files. You need to generate them once (for a particular version) and add to version control. If you need to change the version of Gradle Wrapper, change the version in build.gradle see (1.) and regenerate the files.

    2. Give a detailed example. Such file may have multiple purposes: multi-module project, responsibility separation, slightly modified script, etc.

    3. settings.gradle is responsible rather for structure of the project (modules, names, etc), while, gradle.properties is used for project's and Gradle's external details (version, command line arguments -XX, properties etc.)

    这篇关于如何/何时生成Gradle包装文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆