API 文件 | ArtifactHandler |
---|
此類別用於定義要發布的構件並將其添加到組態中。建立發布構件並不意味著要建立封存檔。建立的是一個領域物件,它表示要發布的檔案以及有關應如何發布的資訊(例如,名稱)。
若要建立發布構件並將其指派給組態,您可以使用以下語法
<configurationName> <artifact-notation>, <artifact-notation> ...
或 <configurationName> <artifact-notation> { ... some code to configure the artifact }
標記法可以是以下類型之一
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
>將構件新增至給定的組態。