Open Source

Other versions of this page

Improve this page on GitHub

Spec artifacts

The contents of a deploy spec (e.g. AARs, JARs, additional artifacts like sources or javadocs) can be configured in the content {} block. Each spec can support multiple components, each one corresponding to a maven publication and pom file.

Built-in components

Inside the content {}, a few utilities are available so that:

  • You give the deployer some hints about the kind of project that you are working on
  • The deployer infers a list of components that you will want to export
Kotlin Multiplatform projects

Use content.kotlinComponents(). The spec will export:

  • One component for Kotlin Metadata (the common target)
  • One component per declared target
  • For Android targets, one component per exported variant
kotlin logokotlin
content { kotlinComponents { // Optional configuration, invoked on each component. } }
Kotlin regular projects

Again, use content.kotlinComponents(). The spec will export:

  • if target is Android, one component per configured variant
  • in all other cases (JS, JVM, ...), one component only
kotlin logokotlin
content { kotlinComponents { // Optional configuration, invoked on the component. } }
Gradle Plugin projects

For projects providing gradle plugins, it is expected that the java-gradle-plugin is applied and that you declare some plugins through the official gradlePlugin { } block. It is also expected that automated publishing is enabled:

kotlin logokotlin
plugins { `java-gradle-plugin` } gradlePlugin { isAutomatedPublishing = true plugins { create("myplugin") { id = "" implementationClass = "" } } }

All of the above are Gradle APIs, not deployer's.

Then, you can use content.gradlePluginComponents() for the deployer spec to collect this data and export it. The spec will be configured to have one component for the project, and one gradle marker component for each plugin in gradlePlugin.plugins. To understand about plugin markers and java-gradle-plugin, please check out Gradle documentation.

kotlin logokotlin
content { gradlePluginComponents { // Optional configuration, invoked on the component. } }

Custom components

To declare custom components, simply add them, one by one, with content.component { ... }. Multiple types of components are supported:

  • Based on an existing Gradle SoftwareComponent
  • Based on an existing Gradle MavenPublication
  • Based on an existing Gradle PluginDeclaration
  • Based on an existing KotlinTarget (except Android targets, which may map to multiple components)
  • A custom list of artifacts
kotlin logokotlin
deployer { content { component { fromSoftwareComponent("softwareComponentName") } component { fromSoftwareComponent(mySoftwareComponentInstance) } component { // cloning the publication makes sure that it can be shared across multiple specs. fromMavenPublication("mavenPublicationName", clone = false) } component { fromKotlinTarget(myKotlinTarget) } component { fromGradlePluginDeclaration(myGradlePlugin) } component { fromJava() // shorthand for fromSoftwareComponent("java") } component { fromArtifactSet { artifact(myArtifact, builtBy = myArtifactTask) artifact(myArtifact, classifier = "data", extension = "zip", builtBy = myArtifactTask) } } } }

Component extras

The component builders mentioned above describe the main published artifact (for example, a jar with binary code). It is possible however to add more files to the publication:

  • sources: use component.sources(mySourcesTask)
  • javadocs: use
  • other artifacts: use component.extras.artifact(...)

You can also leverage sources and docs utilities. Use:

  • content.emptyDocs() to create an empty docs JAR. Useful for repositories that require this artifact to exist.
  • content.emptySources() to create an empty sources JAR. Useful for repositories that require this artifact to exist.
  • content.kotlinSources() to add a Kotlin-based sources JAR. Note that this is not needed for KMP, where sources are automatically exported by the Kotlin Gradle Plugin.
  • content.javaSources() to add a Java-based sources JAR.