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+ }
0 commit comments