Skip to content

Commit

Permalink
Update build.gradle.kts
Browse files Browse the repository at this point in the history
  • Loading branch information
orchestr7 committed Feb 9, 2024
1 parent 8d327e2 commit 1c2badf
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 135 deletions.
136 changes: 1 addition & 135 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -91,142 +92,7 @@ tasks.withType<ReckonCreateTagTask> {
}

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<Jar>("dokkaJar") {
group = "documentation"
archiveClassifier.set("javadoc")
from(tasks.findByName("dokkaHtml"))
}

configure<PublishingExtension> {
publications.withType<MavenPublication>().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("[email protected]")
}
}
scm {
url.set("https://github.com/saveourtool/${project.name}")
connection.set("scm:git:https://github.com/saveourtool/${project.name}.git")
developerConnection.set("scm:git:[email protected]: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<SigningExtension> {
useKeys()
val publications = extensions.getByType<PublishingExtension>().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<StyledTextOutputFactory>().create(logCategory)
Expand Down
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import java.util.Optional

rootProject.name = "okio-extras"

includeBuild("gradle/plugins")

pluginManagement {
repositories {
mavenCentral()
Expand Down

0 comments on commit 1c2badf

Please sign in to comment.