Skip to content

Commit 347a6e6

Browse files
authored
Added nexus-publish plugin (#1751)
This plugin will eventually be used for the migration to the central portal Currently still uses the legacy osshr sonatype location. As the nexus-publish plugin can only be configured in the root project the username and password logic was moved out of conventions/publishing.gradle.kts and into the root buid.gradle.kts. Note: The nexus-publish plugin builds upon the gradle maven-publish plugin so even though the configuration is in the root project, it will only publish projects that use the publishing convention. JAVA-5899
1 parent 7fe2223 commit 347a6e6

File tree

5 files changed

+51
-30
lines changed

5 files changed

+51
-30
lines changed

.evergreen/publish.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ export ORG_GRADLE_PROJECT_signingKey="${SIGNING_KEY}"
1818
export ORG_GRADLE_PROJECT_signingPassword=${SIGNING_PASSWORD}
1919

2020
if [ "$RELEASE" == "true" ]; then
21-
TASK="publishArchives"
21+
TASK="publishArchives closeAndReleaseSonatypeStagingRepository"
2222
else
2323
TASK="publishSnapshots"
2424
fi
2525

26-
SYSTEM_PROPERTIES="-Dorg.gradle.internal.publish.checksums.insecure=true -Dorg.gradle.internal.http.connectionTimeout=120000 -Dorg.gradle.internal.http.socketTimeout=120000"
26+
SYSTEM_PROPERTIES="-Dorg.gradle.internal.publish.checksums.insecure=true"
2727

2828
./gradlew -version
2929
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} # Scala 2.13 is published as result of this gradle execution.

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ time.
8484
## Binaries
8585

8686
Binaries and dependency information for Maven, Gradle, Ivy and others can be found at
87-
[http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.mongodb%22%20AND%20a%3A%22mongodb-driver-sync%22).
87+
[https://central.sonatype.com/search](https://central.sonatype.com/search?namespace=org.mongodb&name=mongodb-driver-sync).
8888

8989
Example for Maven:
9090

@@ -100,12 +100,19 @@ Snapshot builds are also published regulary via Sonatype.
100100
Example for Maven:
101101

102102
```xml
103-
<repositories>
104-
<repository>
105-
<id>sonatype-snapshot</id>
106-
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
107-
</repository>
108-
</repositories>
103+
<repositories>
104+
<repository>
105+
<name>Central Portal Snapshots</name>
106+
<id>central-portal-snapshots</id>
107+
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
108+
<releases>
109+
<enabled>false</enabled>
110+
</releases>
111+
<snapshots>
112+
<enabled>true</enabled>
113+
</snapshots>
114+
</repository>
115+
</repositories>
109116
```
110117

111118
## Build

build.gradle.kts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,37 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import java.time.Duration
1617

1718
plugins {
1819
id("eclipse")
1920
id("idea")
21+
alias(libs.plugins.nexus.publish)
22+
}
23+
24+
val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
25+
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")
26+
27+
nexusPublishing {
28+
packageGroup.set("org.mongodb")
29+
repositories {
30+
sonatype {
31+
username.set(nexusUsername)
32+
password.set(nexusPassword)
33+
34+
// central portal URLs
35+
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
36+
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
37+
}
38+
}
39+
40+
connectTimeout.set(Duration.ofMinutes(5))
41+
clientTimeout.set(Duration.ofMinutes(30))
42+
43+
transitionCheckOptions {
44+
// We have many artifacts and Maven Central can take a long time on its compliance checks.
45+
// Set the timeout for waiting for the repository to close to a comfortable 50 minutes.
46+
maxRetries.set(300)
47+
delayBetween.set(Duration.ofSeconds(10))
48+
}
2049
}

buildSrc/src/main/kotlin/conventions/publishing.gradle.kts

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ plugins {
2828

2929
val signingKey: Provider<String> = providers.gradleProperty("signingKey")
3030
val signingPassword: Provider<String> = providers.gradleProperty("signingPassword")
31-
val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
32-
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")
3331
@Suppress("UNCHECKED_CAST") val gitVersion: Provider<String> = project.findProperty("gitVersion") as Provider<String>
3432

3533
tasks.withType<AbstractPublishToMaven>().configureEach {
@@ -45,25 +43,8 @@ tasks.withType<AbstractPublishToMaven>().configureEach {
4543

4644
val localBuildRepo: Provider<Directory> = rootProject.layout.buildDirectory.dir("repo")
4745

48-
val sonatypeRepositoryReleaseUrl: Provider<String> = provider {
49-
if (version.toString().endsWith("SNAPSHOT")) {
50-
"https://oss.sonatype.org/content/repositories/snapshots/"
51-
} else {
52-
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
53-
}
54-
}
55-
5646
publishing {
5747
repositories {
58-
maven {
59-
url = uri(sonatypeRepositoryReleaseUrl)
60-
if (nexusUsername.isPresent && nexusPassword.isPresent) {
61-
credentials {
62-
username = nexusUsername.get()
63-
password = nexusPassword.get()
64-
}
65-
}
66-
}
6748

6849
// publish to local dir, for artifact tracking and testing
6950
// `./gradlew publishMavenPublicationToLocalBuildRepository`
@@ -141,7 +122,8 @@ tasks.register("publishSnapshots") {
141122
description = "Publishes snapshots to Sonatype"
142123

143124
if (version.toString().endsWith("-SNAPSHOT")) {
144-
dependsOn(tasks.withType<PublishToMavenRepository>())
125+
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
126+
dependsOn(tasks.named("publishToSonatype"))
145127
}
146128
}
147129

@@ -168,7 +150,8 @@ tasks.register("publishArchives") {
168150
}
169151
}
170152
if (gitVersionMatch) {
171-
dependsOn(tasks.withType<PublishToMavenRepository>())
153+
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
154+
dependsOn(tasks.named("publishToSonatype"))
172155
}
173156
}
174157

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ plugin-dokka = "1.8.10"
6464
plugin-download = "5.6.0"
6565
plugin-graalvm = "0.9.23"
6666
plugin-optional-base = "7.0.0"
67+
plugin-nexus-publish = "2.0.0"
6768
plugin-shadow = "8.3.6"
6869
plugin-spotbugs = "6.0.15"
6970
plugin-spotless = "6.14.0"
@@ -207,6 +208,7 @@ download = { id = "de.undercouch.download", version.ref = "plugin-download" }
207208
graalvm-buildtools = { id = "org.graalvm.buildtools.native", version.ref = "plugin-graalvm" }
208209
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
209210
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
211+
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "plugin-nexus-publish" }
210212
optional = { id = "nebula.optional-base", version.ref = "plugin-optional-base" }
211213
shadow = { id = "com.gradleup.shadow", version.ref = "plugin-shadow" }
212214
spotbugs = { id = "com.github.spotbugs", version.ref = "plugin-spotbugs" }

0 commit comments

Comments
 (0)