diff --git a/build-conventions/src/main/kotlin/zcash-sdk.android-conventions.gradle.kts b/build-conventions/src/main/kotlin/zcash-sdk.android-conventions.gradle.kts index 55df4b84..d5545aef 100644 --- a/build-conventions/src/main/kotlin/zcash-sdk.android-conventions.gradle.kts +++ b/build-conventions/src/main/kotlin/zcash-sdk.android-conventions.gradle.kts @@ -1,6 +1,7 @@ import com.android.build.api.dsl.CommonExtension import com.android.build.api.dsl.ManagedVirtualDevice import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions +import java.util.Locale pluginManager.withPlugin("com.android.application") { project.the().apply { @@ -55,6 +56,27 @@ pluginManager.withPlugin("com.android.library") { jacocoVersion = project.property("JACOCO_VERSION").toString() } } + + project.the().apply { + onVariants { variant -> + if (variant.name.toLowerCase(Locale.US).contains("release")) { + variant.packaging.resources.excludes.addAll( + listOf( + "META-INF/ASL2.0", + "META-INF/DEPENDENCIES", + "META-INF/LICENSE", + "META-INF/LICENSE-notice.md", + "META-INF/LICENSE.md", + "META-INF/LICENSE.txt", + "META-INF/NOTICE", + "META-INF/NOTICE.txt", + "META-INF/license.txt", + "META-INF/notice.txt" + ) + ) + } + } + } } pluginManager.withPlugin("com.android.test") { diff --git a/build-conventions/src/main/kotlin/zcash-sdk.publishing-conventions.gradle.kts b/build-conventions/src/main/kotlin/zcash-sdk.publishing-conventions.gradle.kts new file mode 100644 index 00000000..050ea867 --- /dev/null +++ b/build-conventions/src/main/kotlin/zcash-sdk.publishing-conventions.gradle.kts @@ -0,0 +1,111 @@ +import java.util.Base64 + +val publicationVariant = "release" +val isSnapshot = project.property("IS_SNAPSHOT").toString().toBoolean() +val myVersion = project.property("LIBRARY_VERSION").toString() + +val myGroup = "cash.z.ecc.android" +project.group = myGroup + +pluginManager.withPlugin("com.android.library") { + project.the().apply { + publishing { + singleVariant(publicationVariant) { + withSourcesJar() + withJavadocJar() + } + } + } +} + +plugins.withId("org.gradle.maven-publish") { + val publishingExtension = extensions.getByType().apply { + publications { + register("release") { + groupId = myGroup + version = if (isSnapshot) { + "$myVersion-SNAPSHOT" + } else { + myVersion + } + + afterEvaluate { + from(components[publicationVariant]) + } + + pom { + name.set("Zcash Android Wallet SDK") + description.set( + "This lightweight SDK connects Android to Zcash, allowing third-party " + + "Android apps to send and receive shielded transactions easily, securely and privately." + ) + url.set("https://github.com/zcash/zcash-android-wallet-sdk/") + inceptionYear.set("2018") + scm { + url.set("https://github.com/zcash/zcash-android-wallet-sdk/") + connection.set("scm:git:git://github.com/zcash/zcash-android-wallet-sdk.git") + developerConnection.set("scm:git:ssh://git@github.com/zcash/zcash-android-wallet-sdk.git") + } + developers { + developer { + id.set("zcash") + name.set("Zcash") + url.set("https://github.com/zcash/") + } + } + licenses { + license { + name.set("The MIT License") + url.set("http://opensource.org/licenses/MIT") + distribution.set("repo") + } + } + } + } + } + + repositories { + val mavenUrl = if (isSnapshot) { + project.property("ZCASH_MAVEN_PUBLISH_SNAPSHOT_URL").toString() + } else { + project.property("ZCASH_MAVEN_PUBLISH_RELEASE_URL").toString() + } + val mavenPublishUsername = project.property("ZCASH_MAVEN_PUBLISH_USERNAME").toString() + val mavenPublishPassword = project.property("ZCASH_MAVEN_PUBLISH_PASSWORD").toString() + + mavenLocal { + name = "MavenLocal" + } + maven(mavenUrl) { + name = "MavenCentral" + credentials { + username = mavenPublishUsername + password = mavenPublishPassword + } + } + } + } + + plugins.withId("org.gradle.signing") { + project.the().apply { + // Maven Central requires signing for non-snapshots + isRequired = !isSnapshot + + val signingKey = run { + val base64EncodedKey = project.property("ZCASH_ASCII_GPG_KEY").toString() + if (base64EncodedKey.isNotEmpty()) { + val keyBytes = Base64.getDecoder().decode(base64EncodedKey) + String(keyBytes) + } else { + "" + } + } + + if (signingKey.isNotEmpty()) { + useInMemoryPgpKeys(signingKey, "") + } + + sign(publishingExtension.publications) + } + } +} diff --git a/lightwallet-client-lib/build.gradle.kts b/lightwallet-client-lib/build.gradle.kts index 91ea1637..591d4459 100644 --- a/lightwallet-client-lib/build.gradle.kts +++ b/lightwallet-client-lib/build.gradle.kts @@ -19,75 +19,13 @@ plugins { id("maven-publish") id("signing") + id("zcash-sdk.publishing-conventions") } -// Publishing information -val publicationVariant = "release" -val myVersion = project.property("LIBRARY_VERSION").toString() -val myArtifactId = "lightwallet-client" -val isSnapshot = project.property("IS_SNAPSHOT").toString().toBoolean() -project.group = "cash.z.ecc.android" - publishing { publications { - register("release") { - groupId = "cash.z.ecc.android" - artifactId = myArtifactId - version = if (isSnapshot) { - "$myVersion-SNAPSHOT" - } else { - myVersion - } - - afterEvaluate { - from(components[publicationVariant]) - } - - pom { - name.set("Zcash Light Wallet Client") - description.set("Client API for connecting to the Light Wallet server.") - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - inceptionYear.set("2022") - scm { - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - connection.set("scm:git:git://github.com/zcash/zcash-android-wallet-sdk.git") - developerConnection.set("scm:git:ssh://git@github.com/zcash/zcash-android-wallet-sdk.git") - } - developers { - developer { - id.set("zcash") - name.set("Zcash") - url.set("https://github.com/zcash/") - } - } - licenses { - license { - name.set("The MIT License") - url.set("http://opensource.org/licenses/MIT") - distribution.set("repo") - } - } - } - } - } - repositories { - val mavenUrl = if (isSnapshot) { - project.property("ZCASH_MAVEN_PUBLISH_SNAPSHOT_URL").toString() - } else { - project.property("ZCASH_MAVEN_PUBLISH_RELEASE_URL").toString() - } - val mavenPublishUsername = project.property("ZCASH_MAVEN_PUBLISH_USERNAME").toString() - val mavenPublishPassword = project.property("ZCASH_MAVEN_PUBLISH_PASSWORD").toString() - - mavenLocal { - name = "MavenLocal" - } - maven(mavenUrl) { - name = "MavenCentral" - credentials { - username = mavenPublishUsername - password = mavenPublishPassword - } + publications.withType().all { + artifactId = "lightwallet-client" } } } @@ -127,34 +65,6 @@ android { lint { baseline = File("lint-baseline.xml") } - - publishing { - singleVariant(publicationVariant) { - withSourcesJar() - withJavadocJar() - } - } -} - -androidComponents { - onVariants { variant -> - if (variant.name.toLowerCase(Locale.US).contains("release")) { - variant.packaging.resources.excludes.addAll( - listOf( - "META-INF/ASL2.0", - "META-INF/DEPENDENCIES", - "META-INF/LICENSE", - "META-INF/LICENSE-notice.md", - "META-INF/LICENSE.md", - "META-INF/LICENSE.txt", - "META-INF/NOTICE", - "META-INF/NOTICE.txt", - "META-INF/license.txt", - "META-INF/notice.txt" - ) - ) - } - } } tasks.dokkaHtml.configure { diff --git a/sdk-incubator-lib/build.gradle.kts b/sdk-incubator-lib/build.gradle.kts index d7e8c2e3..4e9fe63d 100644 --- a/sdk-incubator-lib/build.gradle.kts +++ b/sdk-incubator-lib/build.gradle.kts @@ -1,5 +1,3 @@ -import java.util.Base64 - plugins { id("com.android.library") id("org.jetbrains.kotlin.android") @@ -12,100 +10,15 @@ plugins { id("maven-publish") id("signing") + id("zcash-sdk.publishing-conventions") } -// Publishing information -val publicationVariant = "release" -val myVersion = project.property("LIBRARY_VERSION").toString() -val myArtifactId = "zcash-android-sdk-incubator" -val isSnapshot = project.property("IS_SNAPSHOT").toString().toBoolean() -val version = project.property("LIBRARY_VERSION").toString() -project.group = "cash.z.ecc.android" - publishing { publications { - register("release") { - artifactId = myArtifactId - groupId = "cash.z.ecc.android" - version = if (isSnapshot) { - "$myVersion-SNAPSHOT" - } else { - myVersion - } - - afterEvaluate { - from(components[publicationVariant]) - } - - pom { - name.set("Zcash Android Wallet SDK In") - description.set("This lightweight SDK connects Android to Zcash, allowing third-party " + - "Android apps to send and receive shielded transactions easily, securely and privately.") - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - inceptionYear.set("2018") - scm { - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - connection.set("scm:git:git://github.com/zcash/zcash-android-wallet-sdk.git") - developerConnection.set("scm:git:ssh://git@github.com/zcash/zcash-android-wallet-sdk.git") - } - developers { - developer { - id.set("zcash") - name.set("Zcash") - url.set("https://github.com/zcash/") - } - } - licenses { - license { - name.set("The MIT License") - url.set("http://opensource.org/licenses/MIT") - distribution.set("repo") - } - } - } + publications.withType().all { + artifactId = "zcash-android-sdk-incubator" } } - repositories { - val mavenUrl = if (isSnapshot) { - project.property("ZCASH_MAVEN_PUBLISH_SNAPSHOT_URL").toString() - } else { - project.property("ZCASH_MAVEN_PUBLISH_RELEASE_URL").toString() - } - val mavenPublishUsername = project.property("ZCASH_MAVEN_PUBLISH_USERNAME").toString() - val mavenPublishPassword = project.property("ZCASH_MAVEN_PUBLISH_PASSWORD").toString() - - mavenLocal { - name = "MavenLocal" - } - maven(mavenUrl) { - name = "MavenCentral" - credentials { - username = mavenPublishUsername - password = mavenPublishPassword - } - } - } -} - -signing { - // Maven Central requires signing for non-snapshots - isRequired = !isSnapshot - - val signingKey = run { - val base64EncodedKey = project.property("ZCASH_ASCII_GPG_KEY").toString() - if (base64EncodedKey.isNotEmpty()) { - val keyBytes = Base64.getDecoder().decode(base64EncodedKey) - String(keyBytes) - } else { - "" - } - } - - if (signingKey.isNotEmpty()) { - useInMemoryPgpKeys(signingKey, "") - } - - sign(publishing.publications) } android { @@ -136,37 +49,8 @@ android { matchingFallbacks += listOf("release") } } - - packagingOptions { - resources.excludes.addAll( - listOf( - "META-INF/DEPENDENCIES", - "META-INF/LICENSE", - "META-INF/LICENSE.txt", - "META-INF/license.txt", - "META-INF/NOTICE", - "META-INF/NOTICE.txt", - "META-INF/notice.txt", - "META-INF/ASL2.0", - "META-INF/LICENSE.md", - "META-INF/LICENSE-notice.md" - ) - ) - } - - lint { - baseline = File("lint-baseline.xml") - } - - publishing { - singleVariant(publicationVariant) { - withSourcesJar() - withJavadocJar() - } - } } - tasks.dokkaHtml.configure { dokkaSourceSets { configureEach { diff --git a/sdk-lib/build.gradle.kts b/sdk-lib/build.gradle.kts index cadb5c89..b5c8bf25 100644 --- a/sdk-lib/build.gradle.kts +++ b/sdk-lib/build.gradle.kts @@ -1,6 +1,3 @@ -import java.util.Base64 -import java.util.Locale - plugins { id("com.android.library") id("org.jetbrains.kotlin.android") @@ -16,100 +13,19 @@ plugins { id("maven-publish") id("signing") + id("zcash-sdk.publishing-conventions") } // Publishing information -val publicationVariant = "release" + val myVersion = project.property("LIBRARY_VERSION").toString() val myArtifactId = "zcash-android-sdk" -val isSnapshot = project.property("IS_SNAPSHOT").toString().toBoolean() -val version = project.property("LIBRARY_VERSION").toString() -project.group = "cash.z.ecc.android" - publishing { publications { - register("release") { + publications.withType().all { artifactId = myArtifactId - groupId = "cash.z.ecc.android" - version = if (isSnapshot) { - "$myVersion-SNAPSHOT" - } else { - myVersion - } - - afterEvaluate { - from(components[publicationVariant]) - } - - pom { - name.set("Zcash Android Wallet SDK") - description.set("This lightweight SDK connects Android to Zcash, allowing third-party " + - "Android apps to send and receive shielded transactions easily, securely and privately.") - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - inceptionYear.set("2018") - scm { - url.set("https://github.com/zcash/zcash-android-wallet-sdk/") - connection.set("scm:git:git://github.com/zcash/zcash-android-wallet-sdk.git") - developerConnection.set("scm:git:ssh://git@github.com/zcash/zcash-android-wallet-sdk.git") - } - developers { - developer { - id.set("zcash") - name.set("Zcash") - url.set("https://github.com/zcash/") - } - } - licenses { - license { - name.set("The MIT License") - url.set("http://opensource.org/licenses/MIT") - distribution.set("repo") - } - } - } } } - repositories { - val mavenUrl = if (isSnapshot) { - project.property("ZCASH_MAVEN_PUBLISH_SNAPSHOT_URL").toString() - } else { - project.property("ZCASH_MAVEN_PUBLISH_RELEASE_URL").toString() - } - val mavenPublishUsername = project.property("ZCASH_MAVEN_PUBLISH_USERNAME").toString() - val mavenPublishPassword = project.property("ZCASH_MAVEN_PUBLISH_PASSWORD").toString() - - mavenLocal { - name = "MavenLocal" - } - maven(mavenUrl) { - name = "MavenCentral" - credentials { - username = mavenPublishUsername - password = mavenPublishPassword - } - } - } -} - -signing { - // Maven Central requires signing for non-snapshots - isRequired = !isSnapshot - - val signingKey = run { - val base64EncodedKey = project.property("ZCASH_ASCII_GPG_KEY").toString() - if (base64EncodedKey.isNotEmpty()) { - val keyBytes = Base64.getDecoder().decode(base64EncodedKey) - String(keyBytes) - } else { - "" - } - } - - if (signingKey.isNotEmpty()) { - useInMemoryPgpKeys(signingKey, "") - } - - sign(publishing.publications) } android { @@ -156,34 +72,6 @@ android { lint { baseline = File("lint-baseline.xml") } - - publishing { - singleVariant(publicationVariant) { - withSourcesJar() - withJavadocJar() - } - } -} - -androidComponents { - onVariants { variant -> - if (variant.name.toLowerCase(Locale.US).contains("release")) { - variant.packaging.resources.excludes.addAll( - listOf( - "META-INF/ASL2.0", - "META-INF/DEPENDENCIES", - "META-INF/LICENSE", - "META-INF/LICENSE-notice.md", - "META-INF/LICENSE.md", - "META-INF/LICENSE.txt", - "META-INF/NOTICE", - "META-INF/NOTICE.txt", - "META-INF/license.txt", - "META-INF/notice.txt" - ) - ) - } - } } allOpen {