Skip to content

Commit 7c006fc

Browse files
Publish: use Nexus Publish plugin, creates staging repo per build.
1 parent 2a639fe commit 7c006fc

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

Jenkinsfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,8 @@ pipeline {
7878
googlechatnotification url: 'id:gchat_java',
7979
message: "*Publishing* ${currentBuild.fullDisplayName} to Central...\n${env.BUILD_URL}"
8080

81-
// Step 1: upload files to staging repository.
8281
// Note: supply internal repo as tests use native dependencies that might not be published, yet.
83-
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsCentral publishMavenJavaPublicationToSonatypeRepository"
84-
85-
// Step 2: close and release staging repository.
86-
sh "./gradlew $gradleArgs $uploadRepoArgsCentral closeAndReleaseRepository"
82+
sh "./gradlew $gradleArgs $internalRepoArgs $uploadRepoArgsCentral publishMavenJavaPublicationToSonatypeRepository closeAndReleaseStagingRepository"
8783

8884
googlechatnotification url: 'id:gchat_java',
8985
message: "Published ${currentBuild.fullDisplayName} successfully to Central - check https://repo1.maven.org/maven2/io/objectbox/ in a few minutes.\n${env.BUILD_URL}"

build.gradle

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ buildscript {
4242
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
4343
// https://github.com/spotbugs/spotbugs-gradle-plugin/releases
4444
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.1"
45-
classpath "io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.22.0"
45+
classpath "io.github.gradle-nexus:publish-plugin:1.0.0"
4646
}
4747
}
4848

@@ -116,24 +116,7 @@ configure(subprojects.findAll { projectNamesToPublish.contains(it.name) }) {
116116
println "WARNING: Can not publish to GitLab: gitlabUrl or gitlabPrivateToken not set."
117117
}
118118
}
119-
maven {
120-
name = 'Sonatype'
121-
url = version.endsWith('SNAPSHOT') ?
122-
"https://oss.sonatype.org/content/repositories/snapshots/" :
123-
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
124-
if (project.hasProperty('sonatypeUsername') && project.hasProperty('sonatypePassword')) {
125-
if (!hasSigningProperties()) {
126-
throw new InvalidUserDataException("To upload to repo signing is required.")
127-
}
128-
129-
credentials {
130-
username = sonatypeUsername
131-
password = sonatypePassword
132-
}
133-
} else {
134-
println "WARNING: Can not publish to Sonatype OSSRH: sonatypeUsername or sonatypePassword not set."
135-
}
136-
}
119+
// Note: Sonatype repo created by publish-plugin.
137120
}
138121

139122
publications {
@@ -178,14 +161,19 @@ wrapper {
178161
distributionType = Wrapper.DistributionType.ALL
179162
}
180163

181-
// Plugin to close and promote staging repository to Central.
182-
apply plugin: 'io.codearte.nexus-staging'
183-
nexusStaging {
184-
if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
185-
println('nexusStaging credentials supplied.')
186-
username = sonatypeUsername
187-
password = sonatypePassword
188-
} else {
189-
println('nexusStaging credentials NOT supplied.')
164+
// Plugin to publish to Central https://github.com/gradle-nexus/publish-plugin/
165+
// This plugin ensures a separate, named staging repo is created for each build when publishing.
166+
apply plugin: "io.github.gradle-nexus.publish-plugin"
167+
nexusPublishing {
168+
repositories {
169+
sonatype {
170+
if (project.hasProperty("sonatypeUsername") && project.hasProperty("sonatypePassword")) {
171+
println('nexusPublishing credentials supplied.')
172+
username = sonatypeUsername
173+
password = sonatypePassword
174+
} else {
175+
println('nexusPublishing credentials NOT supplied.')
176+
}
177+
}
190178
}
191179
}

0 commit comments

Comments
 (0)