Skip to content

Commit dd8f6d2

Browse files
committed
Add publishing scripts
1 parent 9a1bf9b commit dd8f6d2

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
.gradle
33
/local.properties
44
.DS_Store
5+
*/build
56
/build
67
/captures
78
.externalNativeBuild

build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
plugins {
22
kotlin("multiplatform") version "1.6.10"
33
id("com.android.library") version "7.0.3"
4-
id("maven-publish")
4+
id("convention.publication")
55
}
66

77
group = "com.doublesymmetry"
8-
version = "0.0.7"
8+
version = "0.0.1"
99

1010
repositories {
1111
google()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl` // Is needed to turn our build logic written in Kotlin into Gralde Plugin
3+
}
4+
5+
repositories {
6+
gradlePluginPortal() // To use 'maven-publish' and 'signing' plugins in our own plugin
7+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import org.gradle.api.publish.maven.MavenPublication
2+
import org.gradle.api.tasks.bundling.Jar
3+
import org.gradle.kotlin.dsl.`maven-publish`
4+
import org.gradle.kotlin.dsl.signing
5+
import java.util.*
6+
7+
plugins {
8+
id("maven-publish")
9+
id("signing")
10+
}
11+
12+
// Stub secrets to let the project sync and build without the publication values set up
13+
ext["signing.keyId"] = null
14+
ext["signing.password"] = null
15+
ext["signing.secretKeyRingFile"] = null
16+
ext["ossrhUsername"] = null
17+
ext["ossrhPassword"] = null
18+
19+
// Grabbing secrets from local.properties file or from environment variables, which could be used on CI
20+
val secretPropsFile = project.rootProject.file("local.properties")
21+
if (secretPropsFile.exists()) {
22+
secretPropsFile.reader().use {
23+
Properties().apply {
24+
load(it)
25+
}
26+
}.onEach { (name, value) ->
27+
ext[name.toString()] = value
28+
}
29+
} else {
30+
ext["signing.keyId"] = System.getenv("SIGNING_KEY_ID")
31+
ext["signing.password"] = System.getenv("SIGNING_PASSWORD")
32+
ext["signing.secretKeyRingFile"] = System.getenv("SIGNING_SECRET_KEY_RING_FILE")
33+
ext["ossrhUsername"] = System.getenv("OSSRH_USERNAME")
34+
ext["ossrhPassword"] = System.getenv("OSSRH_PASSWORD")
35+
}
36+
37+
val javadocJar by tasks.registering(Jar::class) {
38+
archiveClassifier.set("javadoc")
39+
}
40+
41+
fun getExtraString(name: String) = ext[name].toString()
42+
43+
publishing {
44+
// Configure maven central repository
45+
repositories {
46+
maven {
47+
name = "sonatype"
48+
setUrl("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
49+
credentials {
50+
username = getExtraString("ossrhUsername")
51+
password = getExtraString("ossrhPassword")
52+
}
53+
}
54+
}
55+
56+
// Configure all publications
57+
publications.withType<MavenPublication> {
58+
59+
// Stub javadoc.jar artifact
60+
artifact(javadocJar.get())
61+
62+
// Provide artifacts information requited by Maven Central
63+
pom {
64+
name.set("Multiplatform ViewModel")
65+
description.set("Shared ViewModel in Kotlin Multiplatform")
66+
url.set("https://github.com/doublesymmetry/multiplatform-viewmodel")
67+
68+
licenses {
69+
license {
70+
name.set("Apache-2.0")
71+
url.set("https://opensource.org/licenses/Apache-2.0")
72+
}
73+
}
74+
developers {
75+
developer {
76+
id.set("dcvz")
77+
name.set("David Chavez")
78+
email.set("david@dcvz.io")
79+
}
80+
}
81+
scm {
82+
url.set("https://github.com/doublesymmetry/multiplatform-viewmodel")
83+
}
84+
}
85+
}
86+
}
87+
88+
// Signing artifacts. Signing.* extra properties values will be used
89+
90+
signing {
91+
sign(publishing.publications)
92+
}

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ pluginManagement {
1414
}
1515
}
1616
}
17+
18+
includeBuild("convention-plugins")

0 commit comments

Comments
 (0)