Skip to content

Commit

Permalink
Publish to mavencentral (#144)
Browse files Browse the repository at this point in the history
This PR converts all existing plumbing to upload to Maven Central instead of Bintray. Key changes are:

1. Rename all Bintray/JCenter references to Sonatype/Maven Central
2. Change maven URL
3. Add artifact signing
4. Update pom.xml so it contains all required attributes for Maven Central (see here https://central.sonatype.org/publish/requirements/#sufficient-metadata)
5. Enable publishing of snapshot builds

Relates to #120

Co-authored-by: Gary Peck <[email protected]>
  • Loading branch information
JeroenMols and garyp authored Apr 29, 2021
1 parent 02e66ac commit 8382344
Show file tree
Hide file tree
Showing 16 changed files with 143 additions and 117 deletions.
5 changes: 0 additions & 5 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ on:
paths-ignore:
- '*.md'

push:
branches:
- master
- v[0-9]+.[0-9]+.x

# All jobs need to be kept in sync with their counterparts in release.yaml
jobs:
build:
Expand Down
16 changes: 12 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@ env:
JAVA_VERSION: 11
NODEJS_VERSION: 14
PROTOBUF_VERSION: 3.10.1
BINTRAY_API_USER: ${{ secrets.BINTRAY_API_USER }}
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
SIGNING_KEY_ASCII_ARMORED: ${{ secrets.SIGNING_KEY_ASCII_ARMORED }}
SONATYPE_API_USER: ${{ secrets.SONATYPE_API_USER }}
SONATYPE_API_KEY: ${{ secrets.SONATYPE_API_KEY }}

on:
push:
branches:
- master
- v[0-9]+.[0-9]+.x
tags:
- v[0-9]+.[0-9]+.[0-9]+
- v[0-9]+.[0-9]+.[0-9]+-*
Expand Down Expand Up @@ -241,5 +245,9 @@ jobs:
with:
java-version: ${{ env.JAVA_VERSION }}

- name: Publish to Bintray
run: ./gradlew clean publishToBintrayRepository
# This will publish to the OSSRH Snapshot repository rather than Maven Central if the version
# name ends with -SNAPSHOT.
# The `closeAndReleaseSonatypeStagingRepository` task should be a no-op if publishing a
# snapshot.
- name: Publish to Maven Central
run: ./gradlew clean publishToSonatype closeAndReleaseSonatypeStagingRepository
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ section below under "Usage" for more details.

### Generating Code

> TODO change to Sonatype link after migrating
Pbandk's code generator leverages `protoc`. Download the [latest
protoc](https://github.com/google/protobuf/releases/latest) and make sure `protoc` is on the `PATH`.
Then download the [latest protoc-gen-kotlin self-executing jar
Expand Down Expand Up @@ -327,11 +329,14 @@ protoc \
### Runtime Library

Pbandk's runtime library provides a Kotlin layer over the preferred Protobuf library for each platform. The libraries are
present on JCenter. Using Gradle:
present on Maven Central. Using Gradle:

```
repositories {
jcenter()
// This repository is only needed if using a SNAPSHOT version of pbandk
maven { url "https://s01.oss.sonatype.org/content/repositories/snapshots/" }
mavenCentral()
}
dependencies {
Expand Down Expand Up @@ -590,7 +595,7 @@ To create a new release:
1. Commit the change. E.g.: `git commit -m "Bump to ${VERSION}" -a`.
1. Tag the new version. E.g.: `git tag -a -m "See https://github.com/streem/pbandk/blob/v${VERSION}/CHANGELOG.md" "v${VERSION}"`.
1. Push the changes to GitHub: `git push origin --follow-tags master`.
1. Wait for CI to notice the new tag, build it, and upload it to Bintray.
1. Wait for CI to notice the new tag, build it, and upload it to Maven Central.
1. Create a new release on GitHub. Use the contents of the tag description as the release description. E.g.: `gh release create "v${VERSION}" -F <(git tag -l --format='%(contents)' "v${VERSION}")`.

Then prepare the repository for development of the next version:
Expand Down
34 changes: 34 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import kotlinx.validation.ApiValidationExtension
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
Expand All @@ -11,6 +12,7 @@ plugins {
id("com.google.osdetector") version Versions.osDetectorGradlePlugin apply false

id("binary-compatibility-validator") version Versions.binaryCompatibilityValidatorGradlePlugin
id("io.github.gradle-nexus.publish-plugin") version Versions.nexusPublishGradlePlugin
}

configure<ApiValidationExtension> {
Expand All @@ -20,6 +22,38 @@ configure<ApiValidationExtension> {
nonPublicMarkers.add("pbandk.PbandkInternal")
}

val sonatypeApiUser = providers.gradlePropertyOrEnvironmentVariable("sonatypeApiUser")
val sonatypeApiKey = providers.gradlePropertyOrEnvironmentVariable("sonatypeApiKey")
if (sonatypeApiUser.isPresent && sonatypeApiKey.isPresent) {
configure<NexusPublishExtension> {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
username.set(sonatypeApiUser)
password.set(sonatypeApiKey)
}
}
}
} else {
logger.info("Sonatype API key not defined, skipping configuration of Maven Central publishing repository")
}

val signingKeyAsciiArmored = providers.gradlePropertyOrEnvironmentVariable("signingKeyAsciiArmored")
if (signingKeyAsciiArmored.isPresent) {
subprojects {
plugins.withType<SigningPlugin> {
configure<SigningExtension> {
@Suppress("UnstableApiUsage")
useInMemoryPgpKeys(signingKeyAsciiArmored.get(), "")
sign(extensions.getByType<PublishingExtension>().publications)
}
}
}
} else {
logger.info("PGP signing key not defined, skipping signing configuration")
}

allprojects {
repositories {
mavenCentral()
Expand Down
36 changes: 36 additions & 0 deletions buildSrc/src/main/kotlin/MavenPublicationExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import org.gradle.api.publish.maven.MavenPublication

fun MavenPublication.configurePbandkPom(pomDescription: String) {
val pomName = artifactId
pom {
name.set(pomName)
description.set(pomDescription)
url.set("https://github.com/streem/pbandk")

licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
}
}

organization {
name.set("Streem, LLC")
url.set("https://github.com/streem")
}

developers {
developer {
id.set("streem")
name.set("Streem, LLC")
url.set("https://github.com/streem")
}
}

scm {
connection.set("scm:git:[email protected]:streem/pbandk.git")
developerConnection.set("scm:git:[email protected]:streem/pbandk.git")
url.set("[email protected]:streem/pbandk.git")
}
}
}
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/ProviderFactoryExtensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import com.google.common.base.CaseFormat
import org.gradle.api.provider.Provider
import org.gradle.api.provider.ProviderFactory

/**
* Creates a [Provider] whose value is fetched from the Gradle property named [propertyName], or if there is no such
* Gradle property, then from the environment variable whose name is the ALL_CAPS version of [propertyName]. For
* example, given a [propertyName] of "fooBar", this function will look for an environment variable named "FOO_BAR".
*/
@Suppress("UnstableApiUsage")
fun ProviderFactory.gradlePropertyOrEnvironmentVariable(propertyName: String): Provider<String> {
val envVariableName = CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, propertyName)
return gradleProperty(propertyName)
.forUseAtConfigurationTime()
.orElse(environmentVariable(envVariableName).forUseAtConfigurationTime())
}
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ object Versions {
const val kotlin = "1.4.31"
const val kotlinCoroutines = "1.4.3"
const val kotlinSerialization = "1.1.0"
const val nexusPublishGradlePlugin = "1.1.0"
const val robolectric = "10-robolectric-5803371" // Only update when Android Studio supports Java 11 (11-x requires Java 9)
const val osDetectorGradlePlugin = "1.6.2"
const val protoc = "3.10.1"
Expand Down
57 changes: 0 additions & 57 deletions buildSrc/src/main/kotlin/addBintrayRepository.kt

This file was deleted.

25 changes: 0 additions & 25 deletions buildSrc/src/main/kotlin/configureMavenPom.kt

This file was deleted.

2 changes: 1 addition & 1 deletion examples/browser-js/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ subprojects {
if (System.getenv("CI") == "true") {
mavenLocal()
}
jcenter()
mavenCentral()
}
}
2 changes: 1 addition & 1 deletion examples/custom-service-gen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ subprojects {
if (System.getenv("CI") == "true") {
mavenLocal()
}
jcenter()
mavenCentral()
}

tasks.withType<KotlinCompile>().configureEach {
Expand Down
2 changes: 1 addition & 1 deletion examples/gradle-and-jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repositories {
if (System.getenv("CI") == "true") {
mavenLocal()
}
jcenter()
mavenCentral()
}

application {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ kotlin.code.style=official
kotlin.mpp.stability.nowarn=true
org.gradle.caching=true

# Workaround because Bintray doesn't support *.sha256 and *.sha512 checksum
# Workaround because Maven Central doesn't support *.sha256 and *.sha512 checksum
# files yet. See https://github.com/gradle/gradle/issues/11412 for details.
# Open sonatype issue: https://issues.sonatype.org/browse/NEXUS-23603
systemProp.org.gradle.internal.publish.checksums.insecure=true

# Gradle 6.3+ seem to require a larger metaspace size when run against this
Expand Down
15 changes: 6 additions & 9 deletions protoc-gen-kotlin/jvm/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ plugins {
kotlin("jvm")
application
`maven-publish`
signing
id("org.springframework.boot")
}

description = "Kotlin code generator for Protocol Buffers. This executable runs as a protoc plugin."

application {
mainClassName = "pbandk.gen.MainKt"
applicationName = "protoc-gen-kotlin"
Expand All @@ -21,22 +24,16 @@ tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}

tasks.getByName<BootJar>("bootJar") {
val bootJar by tasks.getting(BootJar::class) {
archiveClassifier.set("jvm8")
launchScript()
}

publishing {
publications {
create<MavenPublication>("bootJar") {
artifact(tasks.getByName("bootJar"))

description = "Executable for pbandk protoc plugin"
pom {
configureForPbandk()
}

addBintrayRepository(project, this)
artifact(bootJar)
configurePbandkPom(project.description!!)
}
}
}
16 changes: 12 additions & 4 deletions protoc-gen-kotlin/lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
plugins {
kotlin("multiplatform")
`maven-publish`
signing
id("com.google.osdetector")
}

description = "Kotlin code generator for Protocol Buffers and library for writing code generator plugins."

kotlin {
jvm {
compilations.all {
Expand Down Expand Up @@ -80,12 +83,17 @@ tasks {
getByName("jvmTest").dependsOn(generateTestProtoDescriptor)
}

// Stub javadoc artifact to satisfy Maven Central requirements. It's only required for the jvm target.
// TODO: replace this with a real javadoc jar generated with Dokka
val jvmJavadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

publishing {
publications.withType<MavenPublication>().configureEach {
description = "Library for pbandk protoc plugin plugins"
pom {
configureForPbandk()
if (artifactId == "protoc-gen-kotlin-lib-jvm") {
artifact(jvmJavadocJar)
}
addBintrayRepository(project, this)
configurePbandkPom(project.description!!)
}
}
Loading

0 comments on commit 8382344

Please sign in to comment.