Skip to content

Configuring what to publish

It is possible to configure publishing for the following Gradle plugins: - com.android.library as single variant library or as multi variant library - org.jetbrains.kotlin.jvm - org.jetbrains.kotlin.multiplatform - java - java-library - java-gradle-plugin - com.gradle.plugin-publish - java-platform - version-catalog

Android Library (multiple variants)

For projects using the com.android.library plugin. This will publish all variants of the project (e.g. both debug and release) or a subset of specified variants.

import com.vanniktech.maven.publish.AndroidMultiVariantLibrary

mavenPublishing {
  // the first parameter represents whether to publish a sources jar
  // the second whether to publish a javadoc jar
  configure(new AndroidMultiVariantLibrary(true, true))
  // or to limit which build types to include
  configure(new AndroidMultiVariantLibrary(true, true, ["beta", "release"]))
  // or to limit which flavors to include, the map key is a flavor dimension, the set contains the flavors
  configure(new AndroidMultiVariantLibrary(true, true, ["beta", "release"], ["store": ["google", "samsung"]]))
}
import com.vanniktech.maven.publish.AndroidMultiVariantLibrary

mavenPublishing {
  configure(AndroidMultiVariantLibrary(
    // whether to publish a sources jar
    sourcesJar = true,
    // whether to publish a javadoc jar
    publishJavadocJar = true,
  ))
  // or
  configure(AndroidMultiVariantLibrary(
    // whether to publish a sources jar
    sourcesJar = true,
    // whether to publish a javadoc jar
    publishJavadocJar = true,
    // limit which build types to include
    includedBuildTypeValues = setOf("beta", "release"),
  ))
  // or
  configure(AndroidMultiVariantLibrary(
    // whether to publish a sources jar
    sourcesJar = true,
    // whether to publish a javadoc jar
    publishJavadocJar = true,
    // limit which build types to include
    includedBuildTypeValues = setOf("beta", "release"),
    // limit which flavors to include, the map key is a flavor dimension, the set contains the flavors
    includedFlavorDimensionsAndValues = mapOf("store" to setOf("google", "samsung")),
  ))
}

Android Library (single variant)

For projects using the com.android.library plugin. Compared to the multi variant version above this will only publish the specified variant instead of publishing all of them.

import com.vanniktech.maven.publish.AndroidSingleVariantLibrary

mavenPublishing {
  // the first parameter represennts which variant is published
  // the second whether to publish a sources jar
  // the third whether to publish a javadoc jar
  configure(new AndroidSingleVariantLibrary("release", true, true))
}
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary

mavenPublishing {
  configure(AndroidSingleVariantLibrary(
    // the published variant
    variant = "release",
    // whether to publish a sources jar
    sourcesJar = true,
    // whether to publish a javadoc jar
    publishJavadocJar = true,
  ))
}

Java Library

For projects using the java-library plugin.

import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  // the first parameter configures the -javadoc artifact, possible values:
  // - `JavadocJar.None()` don't publish this artifact
  // - `JavadocJar.Empty()` publish an emprt jar
  // - `JavadocJar.Javadoc()` to publish standard javadocs
  // the second whether to publish a sources jar
  configure(new JavaLibrary(new JavadocJar.Javadoc(), true))
}
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  configure(JavaLibrary(
    // configures the -javadoc artifact, possible values:
    // - `JavadocJar.None()` don't publish this artifact
    // - `JavadocJar.Empty()` publish an emprt jar
    // - `JavadocJar.Javadoc()` to publish standard javadocs
    javadocJar = JavadocJar.Javadoc(),
    // whether to publish a sources jar
    sourcesJar = true,
  ))
}

Kotlin JVM Library

For projects using the org.jetbrains.kotlin.jvm plugin.

import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  // the first parameter configures the -javadoc artifact, possible values:
  // - `JavadocJar.None()` don't publish this artifact
  // - `JavadocJar.Empty()` publish an emprt jar
  // - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
  // the second whether to publish a sources jar
  configure(new KotlinJvm(new JavadocJar.Dokka("dokkaHtml"), true))
}
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  configure(KotlinJvm(
    // configures the -javadoc artifact, possible values:
    // - `JavadocJar.None()` don't publish this artifact
    // - `JavadocJar.Empty()` publish an emprt jar
    // - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
    javadocJar = JavadocJar.Dokka("dokkaHtml"),
    // whether to publish a sources jar
    sourcesJar = true,
  ))
}

Kotlin Multiplatform Library

For projects using the org.jetbrains.kotlin.multiplatform plugin.

import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  // the parameter configures the -javadoc artifact, possible values:
  // - `JavadocJar.None()` don't publish this artifact
  // - `JavadocJar.Empty()` publish an emprt jar
  // - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
  // the second whether to publish a sources jar
  // the third parameters configures which Android library variants to publish if this project has an Android target
  // defaults to "release" when using the main plugin and nothing for the base plugin
  configure(new KotlinMultiplatform(new JavadocJar.Dokka("dokkaHtml"), true, ["debug", "release"]))
}
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  // sources publishing is always enabled by the Kotlin Multiplatform plugin
  configure(KotlinMultiplatform(
    // configures the -javadoc artifact, possible values:
    // - `JavadocJar.None()` don't publish this artifact
    // - `JavadocJar.Empty()` publish an emprt jar
    // - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
    javadocJar = JavadocJar.Dokka("dokkaHtml"),
    // whether to publish a sources jar
    sourcesJar = true,
    // configure which Android library variants to publish if this project has an Android target
    // defaults to "release" when using the main plugin and nothing for the base plugin
    androidVariantsToPublish = listOf("debug", "release"),
  ))
}

Gradle Plugin

For projects using the java-gradle-plugin plugin. When also using com.gradle.plugin-publish please use GradlePublishPlugin

import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  // the first parameter configures the -javadoc artifact, possible values:
  // - `JavadocJar.None()` don't publish this artifact
  // - `JavadocJar.Empty()` publish an emprt jar
  // - `JavadocJar.Javadoc()` to publish standard javadocs
  // the second whether to publish a sources jar
  configure(new GradlePlugin(new JavadocJar.Javadoc(), true))
}
import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavadocJar

mavenPublishing {
  configure(GradlePlugin(
    // configures the -javadoc artifact, possible values:
    // - `JavadocJar.None()` don't publish this artifact
    // - `JavadocJar.Empty()` publish an emprt jar
    // - `JavadocJar.Javadoc()` to publish standard javadocs
    // - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
    javadocJar = JavadocJar.Javadoc(),
    // whether to publish a sources jar
    sourcesJar = true,
  ))
}

Gradle Publish Plugin

For projects using the com.gradle.plugin-publish plugin. This will always publish a sources jar and a javadoc jar.

import com.vanniktech.maven.publish.GradlePublishPlugin

mavenPublishing {
  configure(new GradlePublishPlugin())
}
import com.vanniktech.maven.publish.GradlePublishPlugin

mavenPublishing {
  configure(GradlePublishPlugin())
}

Java Platform

For projects using the java-platform plugin.

import com.vanniktech.maven.publish.JavaPlatform

mavenPublishing {
  configure(new JavaPlatform())
}
import com.vanniktech.maven.publish.JavaPlatform

mavenPublishing {
  configure(JavaPlatform())
}

Version Catalog

For projects using the version-catalog plugin.

import com.vanniktech.maven.publish.VersionCatalog

mavenPublishing {
  configure(new VersionCatalog())
}
import com.vanniktech.maven.publish.VersionCatalog

mavenPublishing {
  configure(VersionCatalog())
}