-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Critical updates to make gradle plugin work with releases
### What's done: - kotlinx.serialization is updated to 1.5.0 - kotlin is updated to 1.8.21 - release script is converted into the plugin (as suggested in https://kotlinlang.org/docs/multiplatform-library.html#set-up-the-environment). This is needed because gradle became too strict and needs an explicit dependency on signing task now
- Loading branch information
Showing
11 changed files
with
257 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 0 additions & 146 deletions
146
buildSrc/src/main/kotlin/com/akuleshov7/buildutils/PublishingConfiguration.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | ||
|
||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
|
||
dependencies { | ||
implementation("io.github.gradle-nexus:publish-plugin:1.1.0") | ||
} |
157 changes: 157 additions & 0 deletions
157
gradle/plugins/src/main/kotlin/com/saveourtool/save/buildutils/PublishingConfiguration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/** | ||
* Publishing configuration file. | ||
*/ | ||
|
||
@file:Suppress( | ||
"MISSING_KDOC_TOP_LEVEL", | ||
"MISSING_KDOC_ON_FUNCTION", | ||
) | ||
|
||
package com.akuleshov7.buildutils | ||
|
||
import io.github.gradlenexus.publishplugin.NexusPublishExtension | ||
import org.gradle.api.Named | ||
import org.gradle.api.Project | ||
import org.gradle.api.publish.PublishingExtension | ||
import org.gradle.api.publish.maven.MavenPublication | ||
import org.gradle.api.tasks.bundling.Jar | ||
import org.gradle.internal.logging.text.StyledTextOutput | ||
import org.gradle.internal.logging.text.StyledTextOutput.Style.Failure | ||
import org.gradle.internal.logging.text.StyledTextOutput.Style.Success | ||
import org.gradle.internal.logging.text.StyledTextOutputFactory | ||
import org.gradle.kotlin.dsl.configure | ||
import org.gradle.kotlin.dsl.create | ||
import org.gradle.kotlin.dsl.getByType | ||
import org.gradle.kotlin.dsl.support.serviceOf | ||
import org.gradle.kotlin.dsl.withType | ||
import org.gradle.plugins.signing.SigningExtension | ||
|
||
/** | ||
* Enables signing of the artifacts if the `signingKey` project property is set. | ||
* | ||
* Should be explicitly called after each custom `publishing {}` section. | ||
*/ | ||
fun Project.configureSigning() { | ||
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() | ||
} | ||
} | ||
} | ||
|
||
@Suppress("TOO_LONG_FUNCTION") | ||
internal fun Project.configurePublications() { | ||
val dokkaJar: Jar = tasks.create<Jar>("dokkaJar") { | ||
group = "documentation" | ||
archiveClassifier.set("javadoc") | ||
from(tasks.findByName("dokkaHtml")) | ||
} | ||
configure<PublishingExtension> { | ||
repositories { | ||
mavenLocal() | ||
} | ||
publications.withType<MavenPublication>().forEach { publication -> | ||
publication.artifact(dokkaJar) | ||
publication.pom { | ||
name.set(project.name) | ||
description.set(project.description ?: project.name) | ||
url.set("https://github.com/akuleshov7/ktoml") | ||
licenses { | ||
license { | ||
name.set("MIT License") | ||
url.set("https://github.com/akuleshov7/ktoml/blob/main/LICENSE") | ||
distribution.set("repo") | ||
} | ||
} | ||
developers { | ||
developer { | ||
id.set("akuleshov7") | ||
name.set("Andrey Kuleshov") | ||
email.set("andrewkuleshov7@gmail.com") | ||
} | ||
} | ||
scm { | ||
url.set("https://github.com/akuleshov7/ktoml") | ||
connection.set("scm:git:git://github.com/akuleshov7/ktoml.git") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
internal fun Project.configureNexusPublishing() { | ||
configure<NexusPublishExtension> { | ||
repositories { | ||
sonatype { | ||
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/")) | ||
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")) | ||
username.set(property("sonatypeUsername") as String) | ||
password.set(property("sonatypePassword") as String) | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @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 | ||
*/ | ||
private 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()) | ||
} | ||
} | ||
|
||
private fun Project.styledOut(logCategory: String): StyledTextOutput = | ||
serviceOf<StyledTextOutputFactory>().create(logCategory) | ||
|
||
/** | ||
* Determines if this project has all the given properties. | ||
* | ||
* @param propertyNames the names of the properties to locate. | ||
* @return `true` if this project has all the given properties, `false` otherwise. | ||
* @see Project.hasProperty | ||
*/ | ||
private fun Project.hasProperties(vararg propertyNames: String): Boolean = | ||
propertyNames.asSequence().all(this::hasProperty) |
37 changes: 37 additions & 0 deletions
37
...ugins/src/main/kotlin/com/saveourtool/save/buildutils/publishing-configuration.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.akuleshov7.buildutils | ||
|
||
import io.github.gradlenexus.publishplugin.NexusPublishPlugin | ||
import org.gradle.kotlin.dsl.apply | ||
import org.gradle.kotlin.dsl.extra | ||
|
||
plugins { | ||
`maven-publish` | ||
signing | ||
} | ||
|
||
run { | ||
// If present, set properties from env variables. If any are absent, release will fail. | ||
System.getenv("OSSRH_USERNAME")?.let { | ||
extra.set("sonatypeUsername", it) | ||
} | ||
System.getenv("OSSRH_PASSWORD")?.let { | ||
extra.set("sonatypePassword", it) | ||
} | ||
System.getenv("GPG_SEC")?.let { | ||
extra.set("signingKey", it) | ||
} | ||
System.getenv("GPG_PASSWORD")?.let { | ||
extra.set("signingPassword", it) | ||
} | ||
|
||
if (project.path == rootProject.path) { | ||
apply<NexusPublishPlugin>() | ||
if (hasProperty("sonatypeUsername")) { | ||
configureNexusPublishing() | ||
} | ||
} | ||
} | ||
|
||
run { | ||
configurePublications() | ||
} |
Oops, something went wrong.