Skip to content

Commit

Permalink
Update Maven publishing to use nexus publish plugin (#1517)
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored Jul 18, 2024
1 parent 54c6c47 commit 6c314d2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 13 deletions.
28 changes: 28 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import io.github.gradlenexus.publishplugin.NexusPublishExtension
import java.time.Duration

plugins {
id("io.github.gradle-nexus.publish-plugin")
}

// We use gradle-nexus's publish-plugin to publish all of our published artifacts to Maven using OSSRH.
// Documentation for this plugin, see https://github.com/gradle-nexus/publish-plugin/blob/v2.0.0/README.md
// This plugin must be applied at the root project, so we include the following block around the nexus publish
// extension.
rootProject.run {
plugins.apply("io.github.gradle-nexus.publish-plugin")
extensions.getByType(NexusPublishExtension::class.java).run {
this.repositories {
sonatype {
nexusUrl.set(uri("https://aws.oss.sonatype.org/service/local/"))
username.set(properties["ossrhUsername"].toString())
password.set(properties["ossrhPassword"].toString())
}
}

// these are not strictly required. The default timeouts are set to 1 minute. But Sonatype can be really slow.
// If you get the error "java.net.SocketTimeoutException: timeout", these lines will help.
connectTimeout.set(Duration.ofMinutes(3))
clientTimeout.set(Duration.ofMinutes(3))
}
}
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ object Versions {
const val dokka = "1.6.10"
const val kotlin = "1.6.20"
const val ktlintGradle = "10.2.1"
const val nexusPublish = "2.0.0"
const val pig = "0.6.1"
const val shadow = "8.1.1"
}
Expand All @@ -36,6 +37,7 @@ object Plugins {
const val dokka = "org.jetbrains.dokka:dokka-gradle-plugin:${Versions.dokka}"
const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val ktlintGradle = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlintGradle}"
const val nexusPublish = "io.github.gradle-nexus:publish-plugin:${Versions.nexusPublish}"
const val pig = "org.partiql:pig-gradle-plugin:${Versions.pig}"
const val shadow = "com.github.johnrengelman:shadow:${Versions.shadow}"
}
Expand All @@ -45,6 +47,7 @@ dependencies {
implementation(Plugins.dokka)
implementation(Plugins.kotlinGradle)
implementation(Plugins.ktlintGradle)
implementation(Plugins.nexusPublish)
implementation(Plugins.pig)
implementation(Plugins.shadow)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.get
import org.gradle.kotlin.dsl.getByName
import org.gradle.kotlin.dsl.provideDelegate
import org.gradle.plugins.signing.SigningExtension
import org.gradle.plugins.signing.SigningPlugin
import org.jetbrains.dokka.gradle.DokkaPlugin
Expand Down Expand Up @@ -122,7 +121,7 @@ abstract class PublishPlugin : Plugin<Project> {
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
Expand Down Expand Up @@ -160,17 +159,6 @@ abstract class PublishPlugin : Plugin<Project> {
}
}
}
repositories {
maven {
url = uri("https://aws.oss.sonatype.org/service/local/staging/deploy/maven2")
credentials {
val ossrhUsername: String by rootProject
val ossrhPassword: String by rootProject
username = ossrhUsername
password = ossrhPassword
}
}
}
}

// Sign only if publishing to Maven Central
Expand Down

0 comments on commit 6c314d2

Please sign in to comment.