Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publish to mavencentral #144

Merged
merged 9 commits into from
Apr 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realized that we can get snapshot builds more or less for free by just running the "release" workflow for all pushes to the master branch. The nexus-publish gradle plugin automatically chooses whether to publish to the OSSRH snapshot or release repository based on whether the version name includes "-SNAPSHOT".

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`.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See placeholder above so we don't forget to update this link

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/" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JeroenMols FYI, if you ever need to test the latest code on master, every commit to master should now publish artifacts at this maven URL.


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
36 changes: 35 additions & 1 deletion 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,9 +22,41 @@ configure<ApiValidationExtension> {
nonPublicMarkers.add("pbandk.PbandkInternal")
}

val sonatypeApiUser = providers.gradlePropertyOrEnvironmentVariable("sonatypeApiUser")
val sonatypeApiKey = providers.gradlePropertyOrEnvironmentVariable("sonatypeApiKey")
if (sonatypeApiUser.isPresent && sonatypeApiKey.isPresent) {
configure<NexusPublishExtension> {
garyp marked this conversation as resolved.
Show resolved Hide resolved
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 {
jcenter()
mavenCentral()
}

tasks.withType<AbstractTestTask> {
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

repositories {
jcenter()
mavenCentral()
}

dependencies {
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()
garyp marked this conversation as resolved.
Show resolved Hide resolved
}
}
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and this issue still seems to exist


# 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!!)
}
}
}
Loading