Skip to content

Commit

Permalink
Switch to using the nexus publish plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tomdcc committed Jul 30, 2023
1 parent 2148e4d commit 4b88a28
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 22 deletions.
2 changes: 1 addition & 1 deletion RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
- Remove snapshot from version
- Update version numbers in README
- Commit, ensure build is green
- Run `./gradlew clean; ./gradlew publishMavenPublicationToSonatypeStagingRepository -Dorg.gradle.parallel=false`
- Run `./gradlew clean; ./gradlew publishToSonatype -Dorg.gradle.parallel=false`
- Close and release repo in oss.sonatype.org
- `git tag v0.x`
- `git push origin v0.x`
Expand Down
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ groovy = "2.5.18"
# Ratpack looks for org.slf4j.impl.StaticLoggerBinder which is the old discovery mechnanism for slf4j 1.x,
# so we stay on the old version (and this corresponding logback version) to make it be quiet
logback = "1.2.11"
nexus-publish-plugin = "2.0.0-rc-1"
ratpack = "1.10.0-milestone-8"
selenium-api = "3.0.0"
selenium-runtime = "3.141.59"
Expand Down Expand Up @@ -74,6 +75,7 @@ json-simple = { module = "com.googlecode.json-simple:json-simple", version.ref =
jta = { module = "javax.transaction:jta", version.ref = "jta" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
nexus-publish-plugin = { module = "io.github.gradle-nexus:publish-plugin", version.ref = "nexus-publish-plugin" }
selenium-api = { module = "org.seleniumhq.selenium:selenium-api", version.ref = "selenium-api" }
selenium-support = { module = "org.seleniumhq.selenium:selenium-support", version.ref = "selenium-runtime" }
selenium-firefox-driver = { module = "org.seleniumhq.selenium:selenium-firefox-driver", version.ref = "selenium-runtime" }
Expand All @@ -86,5 +88,6 @@ spring-test = { module = "org.springframework:spring-test", version.ref = "sprin
asciidoctor = { id = "org.asciidoctor.jvm.convert", version.ref = "asciidoctor" }
cargo = { id = "com.bmuschko.cargo", version.ref = "cargo-plugin" }
gretty = { id = "org.gretty", version.ref = "gretty" }
nexus-publish = { id = "io.github.gradle-nexus.publish-plugin", version.ref = "nexus-publish-plugin" }
ratpack-java = { id = "io.ratpack.ratpack-java", version.ref = "ratpack" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
1 change: 1 addition & 0 deletions gradle/plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ dependencies {
// another workaround for https://github.com/gradle/gradle/issues/15383
implementation(libs.cargo.plugin)
implementation(libs.gradle.enterprise.plugin)
implementation(libs.nexus.publish.plugin)
}
28 changes: 28 additions & 0 deletions gradle/plugins/src/main/kotlin/build.nexus-publish.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

nexusPublishing {
repositories {
sonatype {
username = project.provider { project.property("sonatypeStagingUsername") as String }
password = project.provider { project.property("sonatypeStagingPassword") as String }
}
}
}
28 changes: 8 additions & 20 deletions gradle/plugins/src/main/kotlin/build.publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
* limitations under the License.
*/

import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.plugins.JavaPluginExtension
import java.net.URI

plugins {
id("base")
id("maven-publish")
Expand All @@ -32,19 +28,6 @@ project.plugins.withId("java") {
}

publishing {
repositories {
maven {
name = "sonatypeStaging"
url = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials(PasswordCredentials::class.java)
}
maven {
name = "sonatypeSnapshots"
url = URI("https://oss.sonatype.org/content/repositories/snapshots/")
credentials(PasswordCredentials::class.java)
}
}

publications {
create<MavenPublication>("maven") {
pom {
Expand All @@ -71,9 +54,14 @@ publishing {
}
}

val isSnapshot = (project.version as String).endsWith("-SNAPSHOT")

signing {
sign(publishing.publications["maven"])
setRequired(project.provider { project.hasProperty("forceSigning") || !(rootProject.extra["isSnapshot"] as Boolean) && gradle.taskGraph.hasTask("${project.path}:publishMavenPublicationToSonatypeStagingRepository") })
setRequired(project.provider {
val publishingToStaging = !isSnapshot && gradle.taskGraph.hasTask("${project.path}:publishToSonatype")
project.hasProperty("forceSigning") || rootProject.extra["isCI"] as Boolean || publishingToStaging
})
}

// disable metadata publication, messes with using the shadow jar
Expand All @@ -82,7 +70,7 @@ tasks.withType<GenerateModuleMetadata> {
}

tasks.register("publishSnapshots") {
if ((project.version as String).endsWith("-SNAPSHOT")) {
dependsOn(tasks.named("publishMavenPublicationToSonatypeSnapshotsRepository"))
if (isSnapshot) {
dependsOn(tasks.named("publishToSonatype"))
}
}
2 changes: 1 addition & 1 deletion miniprofiler-jvm.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ plugins {
alias(libs.plugins.cargo) apply false
alias(libs.plugins.ratpack.java) apply false
id("build.build-scan")
id("build.nexus-publish")
}

allprojects {
Expand All @@ -26,6 +27,5 @@ allprojects {
}

project.the<ExtraPropertiesExtension>().run {
set("isSnapshot", (project.version as String).endsWith("-SNAPSHOT"))
set("isCI", System.getenv("CI") != null)
}

0 comments on commit 4b88a28

Please sign in to comment.