Maven Central
Channels can publish to Maven Central through gradle-maven-publish-plugin 0.34.0 or newer. Apply and configure that plugin as usual. PublishData sets the version and routes each build:
plugins {
`java-library`
id("com.vanniktech.maven.publish") version "0.37.0"
id("de.chojo.publishdata") version "2.1.0"
}
mavenPublishing {
publishToMavenCentral()
signAllPublications()
pom { … }
}
publishData {
channels {
release { publishToMavenCentral() } // tags to Maven Central
snapshot("https://repo.example.com/snapshots") // branches to your snapshot repository
}
}
./gradlew publishChannel
runs publishToMavenCentral on a tag and publishes to the snapshot repository otherwise. A channel can have a
repository and publishToMavenCentral() at once. It then publishes to both.
Things to know
- Use
publishChannel, notpublish. The vanniktech plugin registers its own Central repository, andpublishwould upload branch builds there as well. - The publication and its coordinates come from the vanniktech plugin. Set them with its
coordinates(…).publishData.groupIdandartifactIdonly apply to the publication PublishData creates itself. - Credentials and signing are configured as the vanniktech plugin documents them (
mavenCentralUsername,signingInMemoryKey, …). The snapshot repository takes its credentials throughrepository { }. - With
signAllPublications(), versions ending in-SNAPSHOTare published unsigned when no key is configured. Every other version needs the signing key, also outside Maven Central. Adevchannel (1.5.0-DEV) therefore needs the key on dev branches.branchSuffix()does not. - Release uploads to Maven Central do not support the configuration cache yet, a limit of the vanniktech plugin.
Run them with
--no-configuration-cache. Snapshots work with it. publishToMavenCentral()without the vanniktech plugin is reported as a warning, andpublishChannelfails on the builds that would go to Maven Central.