Skip to content

Commit

Permalink
Close staging repository after artifact upload automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
reisub committed Mar 11, 2021
1 parent b5c54d1 commit 3bcda91
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 15 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ signing.keyId=<GPG_KEY_ID>
signing.password=<GPG_KEY_PASSWORD>
signing.secretKeyRingFile=<GPG_SECRING_LOCATION>
sonatype.url=https://oss.sonatype.org/service/local/staging/deploy/maven2/
sonatype.username=<SONATYPE_USERNAME>
sonatype.password=<SONATYPE_PASSWORD>
sonatypeUrl=https://oss.sonatype.org/service/local/staging/deploy/maven2/
sonatypeUsername=<SONATYPE_USERNAME>
sonatypePassword=<SONATYPE_PASSWORD>
```

To deploy a new version to Maven Central, use `deploy.sh`:
Expand All @@ -61,4 +61,4 @@ To deploy a new version to Maven Central, use `deploy.sh`:
./publish.sh <artifact version> [optional tag message]
```

The publish script will automatically push a tag with the version name and change the version in the README.
The `publish.sh` script will automatically push a tag with the version name and change the version in the README.
21 changes: 21 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.0.0"
}

buildscript {
repositories {
maven { url = uri("https://plugins.gradle.org/m2/") }
Expand All @@ -12,3 +16,20 @@ allprojects {
mavenCentral()
}
}

group = "com.infinum"
version = "3.0.0"

nexusPublishing {
repositories {
sonatype()
}
}

//do not generate extra load on Nexus with new staging repository if signing fails
val initializeSonatypeStagingRepository by tasks.existing
subprojects {
initializeSonatypeStagingRepository {
shouldRunAfter(tasks.withType<Sign>())
}
}
10 changes: 8 additions & 2 deletions publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ set -euo pipefail;

readonly SCRIPT_NAME="$(basename "$0")"
readonly green="\e[0;32m"
readonly red="\e[0;31m"
readonly reset="\e[0m"

if [ $# -lt 1 ]; then
Expand All @@ -36,7 +37,10 @@ if [ -n "${2-}" ]; then
fi

echo -e "${green}Building and uploading release ...${reset}"
./gradlew clean build publishLibraryPublicationToSonatypeRepository
./gradlew clean build publishToSonatype

echo -e "${green}Closing sonatype staging repository ...${reset}"
./gradlew closeSonatypeStagingRepository

echo -e "${green}Pushing version tag ...${reset}"
git tag -a "${version}" -m "${tag_message}" && \
Expand All @@ -48,4 +52,6 @@ sed -E "s/\"com.infinum:retrofit-converter-thrifty:[\.0-9]+\"/\"com.infinum:retr

# show changes so we know to commit if needed
echo -e "${green}\nHere's the output of git status:\n${reset}"
git status
git status

echo -e "${red}\n\nDON'T FORGET to release the artifact on https://oss.sonatype.org/#stagingRepositories !\n${reset}"
15 changes: 6 additions & 9 deletions retrofit-converter-thrifty/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ plugins {
id("signing")
}

group = "com.infinum"
version = "3.0.0"

java {
withJavadocJar()
withSourcesJar()
Expand Down Expand Up @@ -62,19 +59,19 @@ tasks.withType<KotlinCompile>().configureEach {
publishing {
repositories {
maven {
name = "Sonatype"
url = URI.create(project.property("sonatype.url") as String)
name = "MavenCentral"
url = URI.create(project.property("sonatypeUrl") as String)
credentials {
username = project.property("sonatype.username") as String
password = project.property("sonatype.password") as String
username = project.property("sonatypeUsername") as String
password = project.property("sonatypePassword") as String
}
}
}
publications {
create<MavenPublication>("library") {
groupId = project.group as String?
groupId = rootProject.group as String?
artifactId = project.name
version = project.version as String?
version = rootProject.version as String?

from(components["java"])

Expand Down

0 comments on commit 3bcda91

Please sign in to comment.