Skip to content

Commit d2d3b32

Browse files
authored
[build] apply nexus-publish plugin to explicitly create sonatype staging (#561)
Currently Gradle publish task is not using staging repository ID when publishing to Sonatype Maven Central (see: gradle/gradle#5711). Furthermore, Gradle publish does not automatically release artifacts from Sonatype staging directory and requires manual step to finalize the release (i.e. log in to Sonatype repository and release uploaded staged artifacts). As a workaround, in order to automatically publish to Maven Central we need to apply: * `nexus-publish-plugin` - to explicitly create Sonatype staging ID prior to publishing artifacts (needed by `nexus-staging-plugin` to work reliably) * `nexus-staging-plugin` - to explicitly close and release libs triggering the automatic Maven Central release NOTE: It appears that shortcomings of Gradle `maven-publish` plugin are due to their preference of JCenter repository. Based on the documentation it should be possible to configure JCenter to automatically publish staged artifacts and subsequently sync them with Maven Central. If we ever update to publish to JCenter instead we should be able to simplify the build and remove those additional plugins.
1 parent 295a9f9 commit d2d3b32

File tree

4 files changed

+32
-26
lines changed

4 files changed

+32
-26
lines changed

build.gradle.kts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2+
import de.marcphilipp.gradle.nexus.NexusPublishExtension
23
import io.gitlab.arturbosch.detekt.detekt
34
import org.jetbrains.dokka.gradle.DokkaTask
45
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
5-
import java.net.URI
66
import java.time.Instant
77

88
description = "Libraries for running a GraphQL server in Kotlin"
@@ -16,6 +16,7 @@ plugins {
1616
jacoco
1717
signing
1818
`maven-publish`
19+
id("de.marcphilipp.nexus-publish") apply false
1920
id("io.codearte.nexus-staging")
2021
}
2122

@@ -53,8 +54,18 @@ subprojects {
5354
apply(plugin = "java-library")
5455
apply(plugin = "org.jetbrains.dokka")
5556
apply(plugin = "maven-publish")
57+
apply(plugin = "de.marcphilipp.nexus-publish")
5658
apply(plugin = "signing")
5759

60+
configure<NexusPublishExtension> {
61+
repositories {
62+
sonatype {
63+
username.set(System.getenv("SONATYPE_USERNAME"))
64+
password.set(System.getenv("SONATYPE_PASSWORD"))
65+
}
66+
}
67+
}
68+
5869
tasks.withType<KotlinCompile> {
5970
kotlinOptions {
6071
jvmTarget = "1.8"
@@ -106,16 +117,6 @@ subprojects {
106117
dependsOn(dokka.path)
107118
}
108119
publishing {
109-
repositories {
110-
maven {
111-
name = "ossrh"
112-
url = URI.create("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
113-
credentials {
114-
username = System.getenv("SONATYPE_USERNAME")
115-
password = System.getenv("SONATYPE_PASSWORD")
116-
}
117-
}
118-
}
119120
publications {
120121
create<MavenPublication>("mavenJava") {
121122
pom {

docs/contributors/release-proc.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
---
2-
id: release-proc
3-
title: Releasing a new version
4-
---
5-
1. The `pom.xml` should already be `${currentVersion}-SNAPSHOT`
6-
7-
2. Draft a new release and tag the commit (usually just `master`) you want to release as `${currentVersion}` or
8-
increment to a new major/minor version https://github.com/ExpediaDotCom/graphql-kotlin/releases
9-
- When drafting a new release, look at the commit history and comment any new features that were made
10-
- Travis will automatically build on a new tag, change the pom to remove `-SNAPSHOT`, and push the library to Maven
11-
Central
12-
- Travis will create a new branch that bumps the version in both the library and example to
13-
`${nextVersion}-SNAPSHOT`
14-
15-
3. Create a new PR for the Travis branch for the snapshot updates
1+
---
2+
id: release-proc
3+
title: Releasing a new version
4+
---
5+
6+
In order to [release a new version](https://github.com/ExpediaDotCom/graphql-kotlin/releases) we simply need to draft a new release
7+
and tag the commit. Releases are following [semantic versioning](https://semver.org/) and specify major, minor and patch version.
8+
9+
Once release is published it will trigger corresponding [Github Action](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/.github/workflows/release.yml)
10+
based on the published release event. Release workflow will then proceed to build and publish all library artifacts to [Maven Central](https://central.sonatype.org/).
11+
12+
### Release requirements
13+
14+
* tag should specify newly released library version that is following [semantic versioning](https://semver.org/)
15+
* tag and release name should match
16+
* release should contain the information about all the change sets that were included in the given release. We are using `release-drafter` to help automatically
17+
collect this information and generate automatic release notes.

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,5 @@ dokkaVersion = 0.10.0
2626
jacocoVersion = 0.8.5
2727
ktlintVersion = 0.35.0
2828
ktlintPluginVersion = 9.1.1
29+
nexusPublishPluginVersion = 0.3.0
2930
stagingPluginVersion = 0.21.2

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pluginManagement {
33
val dokkaVersion: String by settings
44
val kotlinVersion: String by settings
55
val ktlintPluginVersion: String by settings
6+
val nexusPublishPluginVersion: String by settings
67
val springBootVersion: String by settings
78
val stagingPluginVersion: String by settings
89

@@ -15,6 +16,7 @@ pluginManagement {
1516
id("org.jetbrains.dokka") version dokkaVersion
1617
id("org.springframework.boot") version springBootVersion
1718
id("io.codearte.nexus-staging") version stagingPluginVersion
19+
id("de.marcphilipp.nexus-publish") version nexusPublishPluginVersion
1820
}
1921
}
2022

0 commit comments

Comments
 (0)