api / org.gradle.api.publish.maven / MavenPublication / artifact

artifact

abstract fun artifact(source: Any): MavenArtifact

Creates a custom MavenArtifact to be included in the publication. The artifact method can take a variety of input:

The following example demonstrates the addition of various custom artifacts.
 apply plugin: "maven-publish" task sourceJar(type: Jar) { classifier "sources" } publishing { publications { maven(MavenPublication) { artifact sourceJar // Publish the output of the sourceJar task artifact 'my-file-name.jar' // Publish a file created outside of the build artifact source: sourceJar, classifier: 'src', extension: 'zip' } } } 

Parameters

source - The source of the artifact content.

abstract fun artifact(source: Any, config: Action<in MavenArtifact>): MavenArtifact

Creates an MavenArtifact to be included in the publication, which is configured by the associated action. The first parameter is used to create a custom artifact and add it to the publication, as per #artifact(Object). The created MavenArtifact is then configured using the supplied action, which can override the extension or classifier of the artifact. This method also accepts the configure action as a closure argument, by type coercion.

 apply plugin: "maven-publish" task sourceJar(type: Jar) { classifier "sources" } publishing { publications { maven(MavenPublication) { artifact(sourceJar) { // These values will be used instead of the values from the task. The task values will not be updated. classifier "src" extension "zip" } artifact("my-docs-file.htm") { classifier "documentation" extension "html" } } } } 

Parameters

source - The source of the artifact.

config - An action to configure the values of the constructed MavenArtifact.