Skip to content

Commit 1df3efb

Browse files
committed
Add publishing to Maven Central
1 parent 6b62996 commit 1df3efb

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/TODO*
55

66
/kotlin-js-store
7+
local.properties
78

89
### JetBrains template
910
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm

build.gradle.kts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
import java.util.Properties
2+
import org.gradle.api.publish.maven.MavenPublication
3+
import org.gradle.api.tasks.bundling.Jar
4+
15
plugins {
26
kotlin("multiplatform") version "1.8.0"
7+
id("maven-publish")
8+
id("signing")
39
}
410

511
group = "de.cketti.unicode"
@@ -59,3 +65,83 @@ kotlin {
5965
val nativeTest by getting
6066
}
6167
}
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+
email.set("[email protected]")
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

Comments
 (0)