ArtifactHandler

API 文件ArtifactHandler

此類別用於定義要發布的構件並將其添加到組態中。建立發布構件並不意味著要建立封存檔。建立的是一個領域物件,它表示要發布的檔案以及有關應如何發布的資訊(例如,名稱)。

若要建立發布構件並將其指派給組態,您可以使用以下語法

<configurationName> <artifact-notation>, <artifact-notation> ...<configurationName> <artifact-notation> { ... some code to configure the artifact }

標記法可以是以下類型之一

  • PublishArtifact.
  • AbstractArchiveTask。用於發布構件的資訊是從封存任務中提取的(例如,名稱、副檔名等)。如果需要構件,將會執行該任務。
  • 一個 RegularFileDirectory
  • 一個 ProviderFileRegularFileDirectoryTask,但後者必須定義單一檔案輸出屬性。用於發布構件的資訊是從檔案或目錄名稱中提取的。當提供者表示特定任務的輸出時,如果需要構件,將會執行該任務。
  • 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
}

屬性

無屬性

方法

方法描述
add(configurationName, artifactNotation)

將構件新增至給定的組態。

add(configurationName, artifactNotation, configureClosure)

將構件新增至給定的組態。

add(configurationName, artifactNotation, configureAction)

將構件新增至給定的組態。

腳本區塊

無腳本區塊

方法詳情

PublishArtifact add(String configurationName, Object artifactNotation)

將構件新增至給定的組態。

PublishArtifact add(String configurationName, Object artifactNotation, Closure configureClosure)

將構件新增至給定的組態。

PublishArtifact add(String configurationName, Object artifactNotation, Action<? super ConfigurablePublishArtifact> configureAction)

將構件新增至給定的組態。