From c294c454b7cd04b0f4b01a923a3825d203442207 Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Tue, 6 Dec 2022 19:52:51 +0900 Subject: [PATCH 1/6] Set group and version in build script --- build.gradle.kts | 3 +++ savedstate-ktx/build.gradle.kts | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d7d5d29..d9dbacb 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -13,6 +13,9 @@ buildscript { } allprojects { + group = "io.woong.savedstate" + version = "0.1.0" + repositories { google() mavenCentral() diff --git a/savedstate-ktx/build.gradle.kts b/savedstate-ktx/build.gradle.kts index 6907869..9c3417e 100644 --- a/savedstate-ktx/build.gradle.kts +++ b/savedstate-ktx/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } android { - namespace = "io.woong.savedstate" + namespace = "$group" compileSdk = 33 defaultConfig { From 4848bfb1e08b171762af111026e87ddc34611c0c Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Wed, 7 Dec 2022 21:07:13 +0900 Subject: [PATCH 2/6] Setup maven-publish gradle plugin --- savedstate-ktx/build.gradle.kts | 88 ++++++++++++++++++++++++++++++++- 1 file changed, 87 insertions(+), 1 deletion(-) diff --git a/savedstate-ktx/build.gradle.kts b/savedstate-ktx/build.gradle.kts index 9c3417e..4c9e0b6 100644 --- a/savedstate-ktx/build.gradle.kts +++ b/savedstate-ktx/build.gradle.kts @@ -1,10 +1,13 @@ +import java.util.Properties + plugins { id("org.jetbrains.kotlin.android") id("com.android.library") + id("maven-publish") } android { - namespace = "$group" + namespace = "${project.group}" compileSdk = 33 defaultConfig { @@ -21,6 +24,13 @@ android { kotlinOptions { jvmTarget = JavaVersion.VERSION_1_8.toString() } + + publishing { + singleVariant("release") { + withSourcesJar() + withJavadocJar() + } + } } dependencies { @@ -35,3 +45,79 @@ dependencies { androidTestImplementation("androidx.appcompat:appcompat:1.5.1") androidTestImplementation("androidx.activity:activity-ktx:1.6.1") } + +publishing { + repositories { + maven { + name = "sonatype" + url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") + credentials { + username = property("OSSRH_USERNAME") + password = property("OSSRH_PASSWORD") + } + } + } + + publications { + create("release") { + afterEvaluate { + from(components.getByName("release")) + } + + groupId = "${project.group}" + artifactId = "savedstate-ktx" + version = "${project.version}" + + pom { + name.set("savedstate-ktx") + description.set("Kotlin extensions for Android SavedStateHandle") + url.set("https://github.com/cheonjaewoong/savedstate-ktx") + + licenses { + license { + name.set("MIT") + url.set("https://github.com/cheonjaewoong/savedstate-ktx/blob/master/LICENSE.txt") + } + } + + developers { + developer { + id.set("cheonjaewoong") + name.set("Jaewoong Cheon") + email.set("cheonjaewoong@gmail.com") + } + } + + scm { + url.set("https://github.com/cheonjaewoong/savedstate-ktx") + connection.set("scm:git:git://github.com/cheonjaewoong/savedstate-ktx.git") + developerConnection.set("scm:git:ssh://git@github.com/cheonjaewoong/savedstate-ktx.git") + } + } + } + } +} + +fun property(name: String): String { + return try { + localProperty(name) + } catch (e: Exception) { + environmentVariable(name) + } +} + +fun localProperty(name: String): String { + val localPropertiesFile = project.rootProject.file("local.properties") + if (!localPropertiesFile.exists()) { + throw IllegalStateException("Cannot find 'local.properties' file") + } + val properties = localPropertiesFile.reader().use { reader -> + Properties().apply { load(reader) } + } + val property = properties.getProperty(name, null) + return property ?: throw IllegalArgumentException("Cannot find $name in local.properties") +} + +fun environmentVariable(name: String): String { + return System.getenv(name) +} From 7774c7c34bbb05e6caafb6e4276be8d5da5863c5 Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Wed, 7 Dec 2022 21:16:11 +0900 Subject: [PATCH 3/6] Set initial version to 1.0.0-alpha1 --- build.gradle.kts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle.kts b/build.gradle.kts index d9dbacb..5ea97b5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ buildscript { allprojects { group = "io.woong.savedstate" - version = "0.1.0" + version = "1.0.0-alpha1" repositories { google() From 9cea20ca000220472dd99bd3c08359962cb70d5e Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Wed, 7 Dec 2022 22:10:17 +0900 Subject: [PATCH 4/6] Setup signing gradle plugin --- savedstate-ktx/build.gradle.kts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/savedstate-ktx/build.gradle.kts b/savedstate-ktx/build.gradle.kts index 4c9e0b6..b1cc904 100644 --- a/savedstate-ktx/build.gradle.kts +++ b/savedstate-ktx/build.gradle.kts @@ -4,6 +4,7 @@ plugins { id("org.jetbrains.kotlin.android") id("com.android.library") id("maven-publish") + id("signing") } android { @@ -98,6 +99,19 @@ publishing { } } +signing { + // Try in-memory signing if there are environment variables for signing. + // If not, use local signing key + try { + val key = property("SIGNING_KEY") + val keyPassword = property("SIGNING_PASSWORD") + useInMemoryPgpKeys(key, keyPassword) + } catch (_: Exception) { + println("Use local key to signing artifacts") + } + sign(publishing.publications) +} + fun property(name: String): String { return try { localProperty(name) From 11373277b17202f14f99d35e5e1c2014fddecd3e Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Wed, 7 Dec 2022 22:47:13 +0900 Subject: [PATCH 5/6] Clean up buildscript --- savedstate-ktx/build.gradle.kts | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/savedstate-ktx/build.gradle.kts b/savedstate-ktx/build.gradle.kts index b1cc904..32fa9ca 100644 --- a/savedstate-ktx/build.gradle.kts +++ b/savedstate-ktx/build.gradle.kts @@ -53,8 +53,8 @@ publishing { name = "sonatype" url = uri("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") credentials { - username = property("OSSRH_USERNAME") - password = property("OSSRH_PASSWORD") + username = localProperty("OSSRH_USERNAME") + password = localProperty("OSSRH_PASSWORD") } } } @@ -100,26 +100,9 @@ publishing { } signing { - // Try in-memory signing if there are environment variables for signing. - // If not, use local signing key - try { - val key = property("SIGNING_KEY") - val keyPassword = property("SIGNING_PASSWORD") - useInMemoryPgpKeys(key, keyPassword) - } catch (_: Exception) { - println("Use local key to signing artifacts") - } sign(publishing.publications) } -fun property(name: String): String { - return try { - localProperty(name) - } catch (e: Exception) { - environmentVariable(name) - } -} - fun localProperty(name: String): String { val localPropertiesFile = project.rootProject.file("local.properties") if (!localPropertiesFile.exists()) { @@ -131,7 +114,3 @@ fun localProperty(name: String): String { val property = properties.getProperty(name, null) return property ?: throw IllegalArgumentException("Cannot find $name in local.properties") } - -fun environmentVariable(name: String): String { - return System.getenv(name) -} From 817c04a2ea7a21a95561798ff65e3bbc64222593 Mon Sep 17 00:00:00 2001 From: Jaewoong Cheon Date: Wed, 7 Dec 2022 22:59:00 +0900 Subject: [PATCH 6/6] Change return type of localProperty function to nullable --- savedstate-ktx/build.gradle.kts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/savedstate-ktx/build.gradle.kts b/savedstate-ktx/build.gradle.kts index 32fa9ca..1aeabe5 100644 --- a/savedstate-ktx/build.gradle.kts +++ b/savedstate-ktx/build.gradle.kts @@ -103,14 +103,13 @@ signing { sign(publishing.publications) } -fun localProperty(name: String): String { +fun localProperty(name: String): String? { val localPropertiesFile = project.rootProject.file("local.properties") if (!localPropertiesFile.exists()) { - throw IllegalStateException("Cannot find 'local.properties' file") + return null } val properties = localPropertiesFile.reader().use { reader -> Properties().apply { load(reader) } } - val property = properties.getProperty(name, null) - return property ?: throw IllegalArgumentException("Cannot find $name in local.properties") + return properties.getProperty(name, null) }