Skip to content

Commit dfa4986

Browse files
committed
Added nexus-publish plugin
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 492f883 commit dfa4986

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

build.gradle.kts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,25 @@
1717
plugins {
1818
id("eclipse")
1919
id("idea")
20+
alias(libs.plugins.nexus.publish)
21+
}
22+
23+
val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
24+
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")
25+
26+
nexusPublishing {
27+
packageGroup = "org.mongodb"
28+
repositories {
29+
sonatype {
30+
username = nexusUsername
31+
password = nexusPassword
32+
33+
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
34+
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
35+
36+
// central portal URLs
37+
// nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
38+
// snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
39+
}
40+
}
2041
}

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

Lines changed: 2 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,7 @@ 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("publishToSonatype"))
145126
}
146127
}
147128

@@ -168,7 +149,7 @@ tasks.register("publishArchives") {
168149
}
169150
}
170151
if (gitVersionMatch) {
171-
dependsOn(tasks.withType<PublishToMavenRepository>())
152+
dependsOn(tasks.named("publishToSonatype"))
172153
}
173154
}
174155

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)