From acfaaec7544541b4dabed61afea5b2dcbfb51a48 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Wed, 31 May 2023 23:07:13 +0200 Subject: [PATCH] only enable signing if not snapshot OR running 'publish' task --- .../conventions/publishing.gradle.kts | 127 +++++++++--------- 1 file changed, 65 insertions(+), 62 deletions(-) diff --git a/buildSrc/src/main/kotlin/buildsrc/conventions/publishing.gradle.kts b/buildSrc/src/main/kotlin/buildsrc/conventions/publishing.gradle.kts index 4c26d99..2390479 100644 --- a/buildSrc/src/main/kotlin/buildsrc/conventions/publishing.gradle.kts +++ b/buildSrc/src/main/kotlin/buildsrc/conventions/publishing.gradle.kts @@ -16,87 +16,90 @@ */ package buildsrc.conventions -import org.gradle.api.tasks.bundling.Jar -import org.gradle.kotlin.dsl.creating -import org.gradle.kotlin.dsl.getValue -import org.gradle.kotlin.dsl.version - plugins { - id("maven-publish") - id("signing") - id("org.jetbrains.dokka") + id("maven-publish") + id("signing") + id("org.jetbrains.dokka") } val gitHub = "ethauvin/${rootProject.name}" val mavenUrl = "https://github.com/$gitHub" +val isSnapshotVersion = { project.version.toString().contains("SNAPSHOT") } publishing { - publications { - withType().configureEach { - pom { - name.set("UrlEncoder for Kotlin") - description.set(project.description) - url.set(mavenUrl) - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") - } + publications { + withType().configureEach { + pom { + name.set("UrlEncoder for Kotlin") + description.set(project.description) + url.set(mavenUrl) + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + id.set("gbevin") + name.set("Geert Bevin") + email.set("gbevin@uwyn.com") + url.set("https://github.com/gbevin") + } + developer { + id.set("ethauvin") + name.set("Erik C. Thauvin") + email.set("erik@thauvin.net") + url.set("https://erik.thauvin.net/") + } + } + scm { + connection.set("scm:git://github.com/$gitHub.git") + developerConnection.set("scm:git@github.com:$gitHub.git") + url.set(mavenUrl) + } + issueManagement { + system.set("GitHub") + url.set("$mavenUrl/issues") + } + } } - developers { - developer { - id.set("gbevin") - name.set("Geert Bevin") - email.set("gbevin@uwyn.com") - url.set("https://github.com/gbevin") - } - developer { - id.set("ethauvin") - name.set("Erik C. Thauvin") - email.set("erik@thauvin.net") - url.set("https://erik.thauvin.net/") - } - } - scm { - connection.set("scm:git://github.com/$gitHub.git") - developerConnection.set("scm:git@github.com:$gitHub.git") - url.set(mavenUrl) - } - issueManagement { - system.set("GitHub") - url.set("$mavenUrl/issues") - } - } } - } - repositories { - maven( - if (project.version.toString().contains("SNAPSHOT")) { - uri("https://oss.sonatype.org/content/repositories/snapshots/") - } else { - uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - } - ) { - name = "ossrh" - credentials(PasswordCredentials::class) + repositories { + maven( + if (isSnapshotVersion()) { + uri("https://oss.sonatype.org/content/repositories/snapshots/") + } else { + uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + } + ) { + name = "ossrh" + credentials(PasswordCredentials::class) + } } - } } signing { - useGpgCmd() - sign(publishing.publications) -} + useGpgCmd() + sign(publishing.publications) + setRequired({ + !isSnapshotVersion() || gradle.taskGraph.hasTask("publish") + }) +} +tasks.withType().configureEach { + val signingRequiredPredicate = provider { signing.isRequired } + onlyIf { signingRequiredPredicate.get() } +} // https://youtrack.jetbrains.com/issue/KT-46466 val signingTasks = tasks.withType() tasks.withType().configureEach { - dependsOn(signingTasks) + dependsOn(signingTasks) } val javadocJar by tasks.registering(Jar::class) { - dependsOn(tasks.dokkaJavadoc) - from(tasks.dokkaJavadoc) - archiveClassifier.set("javadoc") + dependsOn(tasks.dokkaJavadoc) + from(tasks.dokkaJavadoc) + archiveClassifier.set("javadoc") }