Gradle 2.0 用户指南翻译——第46章. Java 库发布插件

本文禁止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/91355363

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

第46章. Java 库发布插件

Chapter 46. The Java Library Distribution Plugin

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

Java 库分布插件为 Java 库添加了构建分发 ZIP 的支持。该分发包含了库的JAR文件及其依赖。 
The Java library distribution plugin adds support for building a distribution ZIP for a Java library. The distribution contains the JAR file for the library and its dependencies.

46.1. 用法

46.1. Usage

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

示例 46.1. 使用 Java 库分发插件 - Example 46.1. Using the java library distribution plugin

build.gradle

apply plugin: 'java-library-distribution'

要定义分发的名称,必须设置baseName属性,如下所示: 
To define the name for the distribution you have to set the baseName property as shown below:

示例 46.2. 配置分发的名称 - Example 46.2. Configure the distribution name

build.gradle

distributions {
    main{
        baseName = 'my-name'
    }
}

该插件可以为你的库构建分发。分发将打包库的运行时依赖。所有存储在 src/main/dist 中的文件都将添加到归档分发的根目录中。你可以运行 gradle distZip 来创建包含分发的ZIP。 
The plugin build a distribution for your library. The distribution will package up the runtime dependencies of the library All files stored in src/main/dist will be added to the root of the archive distribution. You can run gradle distZip to create a ZIP containing the distribution.

46.2. 任务

46.2. Tasks

Java 库分发插件向项目添加以下任务。
The Java library distribution plugin adds the following tasks to the project.

表 46.1. Java 库分发插件——任务 - Table 46.1. Java library distribution plugin - tasks

任务名称
Task name
依赖于
Depends on
类型
Type
描述
Description
distZipjarZip创建包含运行时库的完整分发 ZIP 文件。
Creates a full distribution ZIP archive including runtime libraries.

46.3. 在分发中包含其他资源

46.3. Including other resources in the distribution

所有在 src/dist 目录中的文件都会被复制。要在分发中包含任何的静态文件,只需要把它们放到 src/dist 目录,或将其添加到分发的内容中。 
All of the files from the src/dist directory are copied. To include any static files in the distribution, simply arrange them in the src/dist directory, or add it to the content of the distribution.

示例 46.3. 在分发包中包含文件 - Example 46.3. Include files in the distribution

build.gradle

distributions {
    main {
        baseName = 'my-name'
        contents {
            from { 'src/dist' }
        }
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值