diff --git a/build.gradle.kts b/build.gradle.kts index 24dd3ef..e3c8d1e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -21,6 +21,7 @@ plugins { id("org.jetbrains.dokka") version "1.9.10" id("io.gitlab.arturbosch.detekt") id("com.saveourtool.diktat") version "2.0.0" + id("com.saveourtool.buildutils.publishing-configuration") } group = "com.saveourtool" @@ -91,142 +92,7 @@ tasks.withType { } configureDetekt() -configurePublishing() -fun Project.configurePublishing() { - configureGitHubPublishing() - configurePublications() - configureSigning() -} - -fun Project.configureGitHubPublishing() = - publishing { - repositories { - maven { - name = "GitHub" - url = uri("https://maven.pkg.github.com/saveourtool/okio-extras") - credentials { - username = findProperty("gpr.user") as String? ?: System.getenv("GITHUB_ACTOR") - password = findProperty("gpr.key") as String? ?: System.getenv("GITHUB_TOKEN") - } - } - } - } - -fun Project.configurePublications() { - val dokkaJar = tasks.create("dokkaJar") { - group = "documentation" - archiveClassifier.set("javadoc") - from(tasks.findByName("dokkaHtml")) - } - - configure { - publications.withType().configureEach { - this.artifact(dokkaJar) - this.pom { - val project = this@configurePublications - - name.set(project.name) - description.set(project.description ?: project.name) - url.set("https://github.com/saveourtool/${project.name}") - licenses { - license { - name.set("MIT License") - url.set("https://opensource.org/license/MIT") - distribution.set("repo") - } - } - developers { - developer { - id.set("0x6675636b796f75676974687562") - name.set("Andrey Shcheglov") - email.set("shcheglov.av@phystech.edu") - } - } - scm { - url.set("https://github.com/saveourtool/${project.name}") - connection.set("scm:git:https://github.com/saveourtool/${project.name}.git") - developerConnection.set("scm:git:git@github.com:saveourtool/${project.name}.git") - } - } - } - } -} - -/** - * Enables signing of the artifacts if the `signingKey` project property is set. - * - * Should be explicitly called after each custom `publishing {}` section. - */ -fun Project.configureSigning() { - System.getenv("GPG_SEC")?.let { - extra.set("signingKey", it) - } - System.getenv("GPG_PASSWORD")?.let { - extra.set("signingPassword", it) - } - - if (hasProperty("signingKey")) { - /* - * GitHub Actions. - */ - configureSigningCommon { - useInMemoryPgpKeys(property("signingKey") as String?, findProperty("signingPassword") as String?) - } - } else if ( - hasProperties( - "signing.keyId", - "signing.password", - "signing.secretKeyRingFile", - ) - ) { - /*- - * Pure-Java signing mechanism via `org.bouncycastle.bcpg`. - * - * Requires an 8-digit (short form) PGP key id and a present `~/.gnupg/secring.gpg` - * (for gpg 2.1, run - * `gpg --keyring secring.gpg --export-secret-keys >~/.gnupg/secring.gpg` - * to generate one). - */ - configureSigningCommon() - } else if (hasProperty("signing.gnupg.keyName")) { - /*- - * Use an external `gpg` executable. - * - * On Windows, you may need to additionally specify the path to `gpg` via - * `signing.gnupg.executable`. - */ - configureSigningCommon { - useGpgCmd() - } - } -} - -/** - * @param useKeys the block which configures the PGP keys. Use either - * [SigningExtension.useInMemoryPgpKeys], [SigningExtension.useGpgCmd], or an - * empty lambda. - * @see SigningExtension.useInMemoryPgpKeys - * @see SigningExtension.useGpgCmd - */ -@Suppress( - "MaxLineLength", - "SpreadOperator", -) -fun Project.configureSigningCommon(useKeys: SigningExtension.() -> Unit = {}) { - configure { - useKeys() - val publications = extensions.getByType().publications - val publicationCount = publications.size - val message = "The following $publicationCount publication(s) are getting signed: ${publications.map(Named::getName)}" - val style = when (publicationCount) { - 0 -> Failure - else -> Success - } - styledOut(logCategory = "signing").style(style).println(message) - sign(*publications.toTypedArray()) - } -} fun Project.styledOut(logCategory: String): StyledTextOutput = serviceOf().create(logCategory) diff --git a/settings.gradle.kts b/settings.gradle.kts index 46599a2..4cfad81 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -4,6 +4,8 @@ import java.util.Optional rootProject.name = "okio-extras" +includeBuild("gradle/plugins") + pluginManagement { repositories { mavenCentral()