Now works with updated gradle + nexus plugins to publish+release to sonatype OSSRH

This commit is contained in:
nathan 2020-01-04 20:16:10 +01:00
parent 6521c0a440
commit f2fa258f78

View File

@ -9,15 +9,15 @@ plugins {
`maven-publish` `maven-publish`
// publish on sonatype // publish on sonatype
id("de.marcphilipp.nexus-publish") version "0.2.0" id("de.marcphilipp.nexus-publish") version "0.4.0"
// close and release on sonatype // close and release on sonatype
id("io.codearte.nexus-staging") version "0.21.0" id("io.codearte.nexus-staging") version "0.21.1"
id("com.dorkbox.Licensing") version "1.4" id("com.dorkbox.Licensing") version "1.4.2"
id("com.dorkbox.VersionUpdate") version "1.6" id("com.dorkbox.VersionUpdate") version "1.6.1"
id("com.dorkbox.GradleUtils") version "1.2" id("com.dorkbox.GradleUtils") version "1.2.8"
kotlin("jvm") version "1.3.41" kotlin("jvm") version "1.3.61"
} }
object Extras { object Extras {
@ -77,7 +77,7 @@ sourceSets {
} }
repositories { repositories {
mavenLocal() // this must be first! // mavenLocal() // this must be first!
jcenter() jcenter()
} }
@ -148,13 +148,16 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-common") implementation("org.jetbrains.kotlin:kotlin-stdlib-common")
implementation("org.jetbrains.kotlin:kotlin-reflect") implementation("org.jetbrains.kotlin:kotlin-reflect")
val okHttpVer = "4.0.1" val moshiVer = "1.9.2"
val moshiVer = "1.8.0" val okHttpVer = "4.2.2"
val retroVer = "2.6.0" val retroVer = "2.7.0"
implementation("com.squareup.okhttp3:okhttp:$okHttpVer") implementation("com.squareup.okhttp3:okhttp:$okHttpVer")
implementation("com.squareup.okhttp3:logging-interceptor:$okHttpVer") // Log Network Calls implementation("com.squareup.okhttp3:logging-interceptor:$okHttpVer") // Log Network Calls
// better SSL library
implementation("org.conscrypt:conscrypt-openjdk-uber:2.2.1")
// For serialization. THESE ARE NOT TRANSITIVE because it screws up the kotlin version // For serialization. THESE ARE NOT TRANSITIVE because it screws up the kotlin version
implementation("com.squareup.retrofit2:retrofit:$retroVer") implementation("com.squareup.retrofit2:retrofit:$retroVer")
implementation("com.squareup.retrofit2:converter-moshi:$retroVer") implementation("com.squareup.retrofit2:converter-moshi:$retroVer")
@ -223,27 +226,59 @@ publishing {
} }
} }
signing {
setRequired({ project.gradle.taskGraph.hasTask("publishToSonatype") })
repositories { // the home dir for the signing keys are wrong in windows. This makes sure it's consistent
maven { extra["signing.secretKeyRingFile"] = System.getProperty("user.home") + "\\.gnupg\\secring.gpg"
setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2") sign(publishing.publications["maven"])
credentials { }
nexusStaging {
packageGroup = Extras.group
username = Extras.sonatypeUserName username = Extras.sonatypeUserName
password = Extras.sonatypePassword password = Extras.sonatypePassword
} }
nexusPublishing {
packageGroup.set(Extras.group)
repositories {
sonatype {
username.set(Extras.sonatypeUserName)
password.set(Extras.sonatypePassword)
}
} }
} }
task<Task>("Publish & Release to Sonatype") {
group = "publish and release"
tasks.withType<PublishToMavenRepository> { // required to make sure the tasks run in the correct order
onlyIf { tasks["closeAndReleaseRepository"].mustRunAfter(tasks["publishToSonatype"])
publication == publishing.publications["maven"] && repository == publishing.repositories["maven"] dependsOn("publishToSonatype", "closeAndReleaseRepository")
}
} }
tasks.withType<PublishToMavenLocal> { task<Task>("Publish & Release to Maven Local") {
onlyIf { group = "publish and release"
publication == publishing.publications["maven"]
// required to make sure the tasks run in the correct order
dependsOn("publishToMavenLocal")
}
// "hide" all of the irrelevant tasks by un-setting their group (which will cause them NOT to display).
// 'gradle tasks --all' will still show them
project.afterEvaluate {
tasks.forEach {
if (it.group == "release") {
it.apply {
this.group = ""
}
} else if (it.group == "publishing") {
it.apply {
this.group = ""
}
}
} }
} }
@ -261,29 +296,4 @@ publishing {
println("Maven URL: $url$projectName/$name/$version/") println("Maven URL: $url$projectName/$name/$version/")
} }
nexusStaging {
username = Extras.sonatypeUserName
password = Extras.sonatypePassword
}
nexusPublishing {
packageGroup.set(Extras.group)
repositoryName.set("maven")
username.set(Extras.sonatypeUserName)
password.set(Extras.sonatypePassword)
}
signing {
sign(publishing.publications["maven"])
}
task<Task>("publishAndRelease") {
group = "publish and release"
// required to make sure the tasks run in the correct order
tasks["closeAndReleaseRepository"].mustRunAfter(tasks["publishToNexus"])
dependsOn("publishToNexus", "closeAndReleaseRepository")
}
} }