| API文档: | ArtifactHandler |
|---|
此类用于定义要发布的工件并将其添加到配置中。创建发布工件并不意味着创建存档。创建的是一个域对象,它代表要发布的文件以及有关如何发布该文件的信息(例如名称)。
要创建发布工件并将其分配给配置,您可以使用以下语法:
<configurationName> <artifact-notation>, <artifact-notation> ...
或者
<configurationName> <artifact-notation> { ... some code to configure the artifact }
符号可以是以下类型之一:
PublishArtifact。AbstractArchiveTask。用于发布工件的信息是从存档任务中提取的(例如名称、扩展名……)。如果需要工件,则将执行该任务。- 一个
RegularFile或Directory。 - 、或
Provider的一个,限制是后者必须定义单个文件输出属性。用于发布工件的信息是从文件或目录名称中提取的。当提供者表示特定任务的输出时,如果需要工件,则将执行该任务。FileRegularFileDirectoryTask 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配置名称,ObjectartifactNotation)
将工件添加到给定配置。
PublishArtifact add(String配置名称、ObjectartifactNotation、ClosureconfigureClosure)
将工件添加到给定配置。
PublishArtifact add(String配置名称、ObjectartifactNotation、configureAction)Action<? super ConfigurablePublishArtifact>
Action<? super ConfigurablePublishArtifact>将工件添加到给定配置。