|
| 1 | +import java.util.Properties |
| 2 | +import org.gradle.api.publish.maven.MavenPublication |
| 3 | +import org.gradle.api.tasks.bundling.Jar |
| 4 | + |
1 | 5 | plugins {
|
2 | 6 | kotlin("multiplatform") version "1.8.0"
|
| 7 | + id("maven-publish") |
| 8 | + id("signing") |
3 | 9 | }
|
4 | 10 |
|
5 | 11 | group = "de.cketti.unicode"
|
@@ -59,3 +65,83 @@ kotlin {
|
59 | 65 | val nativeTest by getting
|
60 | 66 | }
|
61 | 67 | }
|
| 68 | + |
| 69 | +// Stub secrets to let the project sync and build without the publication values set up |
| 70 | +ext["signing.keyId"] = null |
| 71 | +ext["signing.password"] = null |
| 72 | +ext["signing.secretKeyRingFile"] = null |
| 73 | +ext["ossrhUsername"] = null |
| 74 | +ext["ossrhPassword"] = null |
| 75 | + |
| 76 | +// Grabbing secrets from local.properties file or from environment variables, which could be used on CI |
| 77 | +val secretPropsFile = project.rootProject.file("local.properties") |
| 78 | +if (secretPropsFile.exists()) { |
| 79 | + secretPropsFile.reader().use { |
| 80 | + Properties().apply { |
| 81 | + load(it) |
| 82 | + } |
| 83 | + }.onEach { (name, value) -> |
| 84 | + ext[name.toString()] = value |
| 85 | + } |
| 86 | +} else { |
| 87 | + ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID") |
| 88 | + ext["signing.password"] = System.getenv("SIGNING_PASSWORD") |
| 89 | + ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE") |
| 90 | + ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME") |
| 91 | + ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD") |
| 92 | +} |
| 93 | + |
| 94 | +val javadocJar by tasks.registering(Jar::class) { |
| 95 | + archiveClassifier.set("javadoc") |
| 96 | +} |
| 97 | + |
| 98 | +fun getExtraString(name: String) = ext[name]?.toString() |
| 99 | + |
| 100 | +publishing { |
| 101 | + // Configure maven central repository |
| 102 | + repositories { |
| 103 | + maven { |
| 104 | + name = "sonatype" |
| 105 | + setUrl("https://oss.sonatype.org/service/local/staging/deploy/maven2/") |
| 106 | + credentials { |
| 107 | + username = getExtraString("ossrhUsername") |
| 108 | + password = getExtraString("ossrhPassword") |
| 109 | + } |
| 110 | + } |
| 111 | + } |
| 112 | + |
| 113 | + // Configure all publications |
| 114 | + publications.withType<MavenPublication> { |
| 115 | + // Stub javadoc.jar artifact |
| 116 | + artifact(javadocJar.get()) |
| 117 | + |
| 118 | + // Provide artifacts information requited by Maven Central |
| 119 | + pom { |
| 120 | + name.set("kotlin-codepoints") |
| 121 | + description.set("Kotlin Multiplatform (KMP) library that adds basic support for Unicode code points.") |
| 122 | + url.set("https://github.com/cketti/kotlin-codepoints") |
| 123 | + |
| 124 | + licenses { |
| 125 | + license { |
| 126 | + name.set("MIT") |
| 127 | + url.set("https://opensource.org/licenses/MIT") |
| 128 | + } |
| 129 | + } |
| 130 | + developers { |
| 131 | + developer { |
| 132 | + id.set("cketti") |
| 133 | + name.set("cketti") |
| 134 | + |
| 135 | + } |
| 136 | + } |
| 137 | + scm { |
| 138 | + url.set("https://github.com/cketti/kotlin-codepoints") |
| 139 | + } |
| 140 | + } |
| 141 | + } |
| 142 | +} |
| 143 | + |
| 144 | +// Signing artifacts. Signing.* extra properties values will be used |
| 145 | +signing { |
| 146 | + sign(publishing.publications) |
| 147 | +} |
0 commit comments