Gradle 2.0 用户指南翻译——第四十四章. 分发插件

本文禁止w3cschool转载!

翻译项目请关注Github上的地址:https://github.com/msdx/gradledoc 。

本文翻译所在分支:https://github.com/msdx/gradledoc/tree/2.0 。
更好的阅读体验请访问:http://gradledoc.githang.com/2.0/userguide/userguide.html 。
另外,Android 手机用户可通过我写的一个程序浏览文档,带缓存功能的,目前0.6.1版本兼容 Android 4.0.3以上系统,项目地址如下:
https://github.com/msdx/gradle-doc-apk

翻译不易,本文采用 CC BY-NC-SA 4.0 许可协议,转载请务必署名及注明本文在CSDN博客上的出处:

https://coder.blog.csdn.net/article/details/90764078

关于我对Gradle的翻译,以Github上的项目及http://gradledoc.githang.com 上的文档为准。如发现翻译有误的地方,将首先在以上两个地方更新。因时间精力问题,博客中发表的译文基本不会同步修改。

 

第四十四章. 分发插件

Chapter 44. The Distribution Plugin

分发插件目前是一个试验性插件。注意,在以后的 Gradle 版本中,其 DSL 和其他配置可能会有变化。 
The distribution plugin is currently incubating. Please be aware that the DSL and other configuration may change in later Gradle versions.

分发插件有助于构建用作项目分发的档案。分发档案通常包含可执行程序和其他支持文件,比如文档。 
The distribution plugin facilitates building archives that serve as distributions of the project. Distribution archives typically contain then executable application and other supporting files, such as documentation.

44.1. 用法

44.1. Usage

要使用分发插件,请在构建脚本中包含:
To use the distribution plugin, include in your build script:

示例 44.1. 使用分发插件 - Example 44.1. Using the distribution plugin

build.gradle

apply plugin: 'distribution'

本插件向项目添加了一个名为“distributions”的DistributionContainer类型的扩展。它还在分发容器扩展中创建了一个名为“main”的单个distribution。如果您的构建只生成一个分发,则你只需要配置这一个distribution(或使用默认值)。 
The plugin adds an extension named "distributions" of type DistributionContainer to the project. It also creates a single distribution in the distributions container extension named "main". If your build only produces one distribution you only need to configure this distribution (or use the defaults).

你可以运行“gradle distZip”把 main distribution 打包为 ZIP,或者是运行“gradle distTar”来创建一个 GZip 压缩的 TAR 文件。这些文件将会创建在“$buildDir/distributions/$project.name-$project.version.«ext»”。 
You can run "gradle distZip" to package the main distribution as a ZIP, or "gradle distTar" to create a GZip compressed TAR file. The files will be created at "$buildDir/distributions/$project.name-$project.version.«ext»".

你可以运行“gradle installDist”将未经压缩的分发内容组装到“$buildDir/install/main”。 
You can run "gradle installDist" to assembles the distribution content, uncompressed, into "$buildDir/install/main".

44.2. 任务

44.2. Tasks

分发插件将以下以下任务添加到项目中:
The Distribution plugin adds the following tasks to the project:

表 44.1. 分发插件——任务 - Table 44.1. Distribution plugin - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
distZip-Zip创建分发内容的 ZIP 存档 
Creates a ZIP archive of the distribution contents
distTar-Tar创建分发内容的 ZIP 存档 
Creates a ZIP archive of the distribution contents
installDist-Sync组装分发内容,并将其安装在当前计算机上 
Assembles the distribution content and installs it on the current machine

对于你向项目中添加的每一个额外的分发集,分发插件都会添加以下任务:
For each extra distribution set you add to the project, the distribution plugin adds the following tasks:

表 44.2. 多分发——任务 - Table 44.2. Multiple distributions - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
${distribution.name}DistZip-Zip创建分发内容的 ZIP 存档 
Creates a ZIP archive of the distribution contents
${distribution.name}DistTar-Tar创建分发内容的 TAR 文件 
Creates a TAR archive of the distribution contents
install${distribution.name.capitalize()}Dist-Sync组装分发内容,并将其安装在当前计算机上 
Assembles the distribution content and installs it on the current machine

示例 44.2. 添加额外的分发 - Example 44.2. Adding extra distributions

build.gradle

apply plugin: 'distribution'

version = '1.2'
distributions {
    custom {}
}

这将向项目添加以下任务: 
This will add following tasks to the project:

  • customDistZip
  • customDistTar
  • installCustomDist

 

鉴于项目的名称是“myproject”,版本为“1.2”,运行“gradle customDistZip”将会产生一个名为“myproject-custom-1.2.zip”的 ZIP 文件。 
Given that the project name is "myproject" and version "1.2", running "gradle customDistZip" will produce a ZIP file named "myproject-custom-1.2.zip".

运行“gradle installCustomDist”将会把分发内容安装到“$buildDir/install/custom”。 
Running "gradle installCustomDist" will install the distribution contents into "$buildDir/install/custom".

44.3. 分发内容

44.3. Distribution contents

src/$distribution.name/dist”目录中的所有文件都会被自动包含在分发中。你可以通过配置作为容器中的一部分的Distribution对象来添加其他文件。 
All of the files in the "src/$distribution.name/dist" directory will automatically be included in the distribution. You can add additional files by configuring the Distribution object that is part of the container.

示例 44.3. 配置 main distribution - Example 44.3. Configuring the main distribution

build.gradle

apply plugin: 'distribution'

distributions {
    main {
        baseName = 'someName'
        contents {
            from { 'src/readme' }
        }
    }
}

在上面的示例中,“src/readme”目录的内容将被包含进 distribution(与默认添加的“src/dist/main”目录中的文件一起)。 
In the example above, the content of the "src/readme" directory will be included in the distribution (along with the files in the "src/dist/main" directory which are added by default).

baseName”属性也被修改了。这将导致分发的存档以不同的名字创建。 
The "baseName" property has also been changed. This will cause the distribution archives to be created with a different name.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值