artifact
Creates a custom MavenArtifact to be included in the publication. The artifact
method can take a variety of input:
- A org.gradle.api.artifacts.PublishArtifact instance. Extension and classifier values are taken from the wrapped instance.
- An org.gradle.api.tasks.bundling.AbstractArchiveTask instance. Extension and classifier values are taken from the wrapped instance.
- Anything that can be resolved to a java.io.File via the file method. Extension and classifier values are interpolated from the file name.
- A java.util.Map that contains a 'source' entry that can be resolved as any of the other input types, including file. This map can contain a 'classifier' and an 'extension' entry to further configure the constructed artifact.
plugins {
id 'maven-publish'
}
task sourceJar(type: Jar) {
archiveClassifier = "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'
}
}
}
Content copied to clipboard
Parameters
source
The source of the artifact content.
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. 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.
plugins {
id 'maven-publish'
}
task sourceJar(type: Jar) {
archiveClassifier = "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"
}
}
}
}
Content copied to clipboard
Parameters
source
The source of the artifact.
config
An action to configure the values of the constructed MavenArtifact.