API 文档 | ArtifactHandler |
---|
此类用于定义要发布的工件,并将其添加到配置中。创建发布工件并不意味着创建存档。这里创建的是一个表示要发布的文件以及如何发布(例如名称)信息的领域对象。
要创建发布工件并将其分配给配置,可以使用以下语法:
<configurationName> <artifact-notation>, <artifact-notation> ...
或 <configurationName> <artifact-notation> { ... 配置工件的一些代码 }
符号可以是以下类型之一:
PublishArtifact
.AbstractArchiveTask
。发布工件的信息是从归档任务中提取的(例如名称、扩展名等)。如果需要该工件,则会执行该任务。- 一个
RegularFile
或Directory
。 - 一个
Provider
,其类型为File
、RegularFile
、Directory
或Task
,但后者必须定义单个文件输出属性。发布工件的信息从文件或目录名称中提取。当提供者表示特定任务的输出时,如果需要该工件,则会执行该任务。 File
。发布工件的信息从文件名中提取。Map
。Map 应该包含一个 'file' 键。这将被转换为上面描述的工件。您还可以使用 Map 中的条目指定工件的其他属性。
在每种情况下,都会为工件创建一个 ConfigurablePublishArtifact
实例,以允许配置工件属性。您还可以使用闭包来配置工件实例的属性,从而覆盖工件属性的默认值。
一个示例,展示如何通过工件处理器将归档任务与配置关联起来。这样,归档就可以通过配置发布或在其他项目中引用。
configurations { //declaring new configuration that will be used to associate with artifacts schema } task schemaJar(type: Jar) { //some imaginary task that creates a jar artifact with some schema } //associating the task that produces the artifact with the configuration artifacts { //configuration name and the task: schema schemaJar }
PublishArtifact
add
(String
configurationName, Object
artifactNotation)
向给定配置添加工件。
PublishArtifact
add
(String
configurationName, Object
artifactNotation, Closure
configureClosure)
向给定配置添加工件。
PublishArtifact
add
(String
configurationName, Object
artifactNotation, Action
<? super ConfigurablePublishArtifact
>
configureAction)
Action
<? super ConfigurablePublishArtifact
>向给定配置添加工件。