Configuring what to publish¶
It is possible to configure publishing for the following Gradle plugins:
com.android.libraryas single variant library or as multi variant librarycom.android.fused-libraryorg.jetbrains.kotlin.jvmorg.jetbrains.kotlin.multiplatform- automatically includes
com.android.kotlin.multiplatform.library
- automatically includes
javajava-libraryjava-gradle-plugincom.gradle.plugin-publishjava-platformversion-catalog
Automatic plugin selection¶
To automatically select what to publish based on already applied plugins call
configureBasedOnAppliedPlugins(...). This is called automatically by the
com.vanniktech.maven.publish plugin, you only need to call this yourself when
using com.vanniktech.maven.publish.base or when you want to configure the
sources and javadoc jars that are being published.
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configureBasedOnAppliedPlugins(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources()
)
}
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configureBasedOnAppliedPlugins(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
)
}
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
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new AndroidMultiVariantLibrary(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources()
))
// or
configure(new AndroidMultiVariantLibrary(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources(),
// limit which build types to include
["beta", "release"] as Set
))
// or
configure(new AndroidMultiVariantLibrary(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources(),
// limit which build types to include
["beta", "release"] as Set,
// limit which flavors to include
// the map key is a flavor dimension, the set contains the flavors
["store": ["google", "samsung"] as Set]
))
}
import com.vanniktech.maven.publish.AndroidMultiVariantLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(AndroidMultiVariantLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
))
// or
configure(AndroidMultiVariantLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
// limit which build types to include
includedBuildTypeValues = setOf("beta", "release"),
))
// or
configure(AndroidMultiVariantLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
// 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
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new AndroidSingleVariantLibrary(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources(),
// which variant is published
"release"
))
}
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(AndroidSingleVariantLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
// the published variant
variant = "release",
))
}
Android Fused Library¶
For projects using the com.android.fused-library plugin.
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new AndroidFusedLibrary())
}
import com.vanniktech.maven.publish.AndroidFusedLibrary
mavenPublishing {
configure(AndroidFusedLibrary())
}
Warning
Support for Android fused libraries is considered experimental and might break with future Android Gradle plugin updates.
Warning
Signing is currently unsupported for Android fused libraries because of an issue in the Android Gradle plugin.
Info
Configuring source and javadoc publishing is currently not possible. For javadoc jars the plugin will always publish empty jars. For the sources jar the plugin will publish and empty jar for Android Gradle Plugin 8.x and a jar produced automatically by the Android Gradle Plugin on version 9.0 and newer.
Java Library¶
For projects using the java-library plugin.
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new JavaLibrary(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources()
))
}
import com.vanniktech.maven.publish.JavaLibrary
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(JavaLibrary(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty jar
// - `JavadocJar.Javadoc()` to publish standard javadocs
javadocJar = JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
))
}
Kotlin JVM Library¶
For projects using the org.jetbrains.kotlin.jvm plugin.
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new KotlinJvm(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources()
))
}
import com.vanniktech.maven.publish.KotlinJvm
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(KotlinJvm(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
))
}
Kotlin Multiplatform Library¶
For projects using the org.jetbrains.kotlin.multiplatform plugin.
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new KotlinMultiplatform(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty jar
// - `JavadocJar.Dokka("dokkaHtml")` when using Kotlin with Dokka, where `dokkaHtml` is the name of the Dokka task that should be used as input
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources(),
// 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
["debug", "release"]
))
}
import com.vanniktech.maven.publish.KotlinMultiplatform
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
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 empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
// 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"),
))
}
Info
The com.android.kotlin.multiplatform.library plugin does not need any special configuration. When using it
leave out the third parameter (androidVariantsToPublish) of KotlinMultiplatform.
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
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(new GradlePlugin(
// the first parameter configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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
new JavadocJar.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
new SourcesJar.Sources()
))
}
import com.vanniktech.maven.publish.GradlePlugin
import com.vanniktech.maven.publish.JavadocJar
import com.vanniktech.maven.publish.SourcesJar
mavenPublishing {
configure(GradlePlugin(
// configures the -javadoc artifact, possible values:
// - `JavadocJar.None()` don't publish this artifact
// - `JavadocJar.Empty()` publish an empty 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.Empty(),
// configures the -sources artifact, possible values:
// - `SourcesJar.None()` don't publish this artifact
// - `SourcesJar.Empty()` publish an empty jar
// - `SourcesJar.Sources()` publish the sources
sourcesJar = SourcesJar.Sources(),
))
}
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())
}