Skip to content

Added nexus-publish plugin #1751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .evergreen/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ export ORG_GRADLE_PROJECT_signingKey="${SIGNING_KEY}"
export ORG_GRADLE_PROJECT_signingPassword=${SIGNING_PASSWORD}

if [ "$RELEASE" == "true" ]; then
TASK="publishArchives"
TASK="publishArchives closeAndReleaseSonatypeStagingRepository"
else
TASK="publishSnapshots"
fi

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

./gradlew -version
./gradlew ${SYSTEM_PROPERTIES} --stacktrace --info ${TASK} # Scala 2.13 is published as result of this gradle execution.
Expand Down
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ time.
## Binaries

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

Example for Maven:

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

```xml
<repositories>
<repository>
<id>sonatype-snapshot</id>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>
</repositories>
<repositories>
<repository>
<name>Central Portal Snapshots</name>
<id>central-portal-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
```

## Build
Expand Down
29 changes: 29 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,37 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import java.time.Duration

plugins {
id("eclipse")
id("idea")
alias(libs.plugins.nexus.publish)
}

val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")

nexusPublishing {
packageGroup.set("org.mongodb")
repositories {
sonatype {
username.set(nexusUsername)
password.set(nexusPassword)

// central portal URLs
nexusUrl.set(uri("https://ossrh-staging-api.central.sonatype.com/service/local/"))
snapshotRepositoryUrl.set(uri("https://central.sonatype.com/repository/maven-snapshots/"))
}
}

connectTimeout.set(Duration.ofMinutes(5))
clientTimeout.set(Duration.ofMinutes(30))

transitionCheckOptions {
// We have many artifacts and Maven Central can take a long time on its compliance checks.
// Set the timeout for waiting for the repository to close to a comfortable 50 minutes.
maxRetries.set(300)
delayBetween.set(Duration.ofSeconds(10))
}
}
25 changes: 4 additions & 21 deletions buildSrc/src/main/kotlin/conventions/publishing.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ plugins {

val signingKey: Provider<String> = providers.gradleProperty("signingKey")
val signingPassword: Provider<String> = providers.gradleProperty("signingPassword")
val nexusUsername: Provider<String> = providers.gradleProperty("nexusUsername")
val nexusPassword: Provider<String> = providers.gradleProperty("nexusPassword")
@Suppress("UNCHECKED_CAST") val gitVersion: Provider<String> = project.findProperty("gitVersion") as Provider<String>

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

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

val sonatypeRepositoryReleaseUrl: Provider<String> = provider {
if (version.toString().endsWith("SNAPSHOT")) {
"https://oss.sonatype.org/content/repositories/snapshots/"
} else {
"https://oss.sonatype.org/service/local/staging/deploy/maven2/"
}
}

publishing {
repositories {
maven {
url = uri(sonatypeRepositoryReleaseUrl)
if (nexusUsername.isPresent && nexusPassword.isPresent) {
credentials {
username = nexusUsername.get()
password = nexusPassword.get()
}
}
}

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

if (version.toString().endsWith("-SNAPSHOT")) {
dependsOn(tasks.withType<PublishToMavenRepository>())
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
dependsOn(tasks.named("publishToSonatype"))
}
}

Expand All @@ -168,7 +150,8 @@ tasks.register("publishArchives") {
}
}
if (gitVersionMatch) {
dependsOn(tasks.withType<PublishToMavenRepository>())
dependsOn(tasks.named("publishAllPublicationsToLocalBuildRepository"))
dependsOn(tasks.named("publishToSonatype"))
}
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ plugin-dokka = "1.8.10"
plugin-download = "5.6.0"
plugin-graalvm = "0.9.23"
plugin-optional-base = "7.0.0"
plugin-nexus-publish = "2.0.0"
plugin-shadow = "8.3.6"
plugin-spotbugs = "6.0.15"
plugin-spotless = "6.14.0"
Expand Down Expand Up @@ -207,6 +208,7 @@ download = { id = "de.undercouch.download", version.ref = "plugin-download" }
graalvm-buildtools = { id = "org.graalvm.buildtools.native", version.ref = "plugin-graalvm" }
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "plugin-nexus-publish" }
optional = { id = "nebula.optional-base", version.ref = "plugin-optional-base" }
shadow = { id = "com.gradleup.shadow", version.ref = "plugin-shadow" }
spotbugs = { id = "com.github.spotbugs", version.ref = "plugin-spotbugs" }
Expand Down