artifact

abstract fun artifact(source: Any): IvyArtifact(source)

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

  • A org.gradle.api.artifacts.PublishArtifact instance. Name, type, extension and classifier values are taken from the supplied instance.
  • An org.gradle.api.tasks.bundling.AbstractArchiveTask instance. Name, type, extension and classifier values are taken from the supplied instance.
  • Anything that can be resolved to a java.io.File via the file method. Name, 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 additional attributes to further configure the constructed artifact.
The following example demonstrates the addition of various custom artifacts.
plugins {
    id 'ivy-publish'
}

task sourceJar(type: Jar) {
  archiveClassifier = "source"
}

task genDocs {
  doLast {
    // Generate 'my-docs-file.htm'
  }
}

publishing {
  publications {
    ivy(IvyPublication) {
      artifact sourceJar // Publish the output of the sourceJar task
      artifact 'my-file-name.jar' // Publish a file created outside of the build
      artifact source: 'my-docs-file.htm', classifier: 'docs', extension: 'html', builtBy: genDocs // Publish a file generated by the 'genDocs' task
    }
  }
}

Parameters

source

The source of the artifact content.


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

Creates an IvyArtifact 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 IvyArtifact is then configured using the supplied action. This method also accepts the configure action as a closure argument, by type coercion.

plugins {
    id 'ivy-publish'
}

task sourceJar(type: Jar) {
  archiveClassifier = "source"
}

task genDocs {
  doLast {
    // Generate 'my-docs-file.htm'
  }
}

publishing {
  publications {
    ivy(IvyPublication) {
      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"
        conf = "runtime->default"
      }
      artifact("my-docs-file.htm") {
        type = "documentation"
        extension = "html"
        builtBy genDocs
      }
    }
  }
}

Parameters

source

The source of the artifact.

config

An action to configure the values of the constructed IvyArtifact.