From 80a1fe5b533663ab20897e449160465feabd709b Mon Sep 17 00:00:00 2001 From: Harun Wangereka Date: Mon, 20 Jun 2022 19:20:03 +0300 Subject: [PATCH 1/3] Updated AGP and Kotlin version --- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle.kts | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index be1aa6b..67f97e4 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip diff --git a/settings.gradle.kts b/settings.gradle.kts index d68980d..5694b2a 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,17 +5,17 @@ pluginManagement { } plugins { - id("com.android.application") version "7.0.1" - id("org.jetbrains.kotlin.android") version "1.4.21" - id("org.jetbrains.kotlin.android.extensions") version "1.4.10" - id("com.android.library") version "7.0.1" + id("com.android.application") version "7.2.1" + id("org.jetbrains.kotlin.android") version "1.7.0" + id("org.jetbrains.kotlin.android.extensions") version "1.7.0" + id("com.android.library") version "7.2.1" id("com.google.firebase.crashlytics") version "2.1.0" } resolutionStrategy { eachPlugin { when (requested.id.id) { - "com.android.application", "com.android.library" -> useModule("com.android.tools.build:gradle:7.0.1") + "com.android.application", "com.android.library" -> useModule("com.android.tools.build:gradle:7.2.1") "com.google.firebase.crashlytics" -> useModule("com.google.firebase:firebase-crashlytics-gradle:2.1.0") } } From 8a8f7c7d4ab8975974c71e402df010d859b2b3e8 Mon Sep 17 00:00:00 2001 From: Harun Wangereka Date: Mon, 20 Jun 2022 22:52:27 +0300 Subject: [PATCH 2/3] Added publishing steps --- app/build.gradle.kts | 2 - build.gradle.kts | 4 +- buildSrc/src/main/kotlin/Dependencies.kt | 2 + daraja/build.gradle.kts | 135 +++++++++++++++++++++-- daraja/gradle.properties | 1 + settings.gradle.kts | 1 - 6 files changed, 132 insertions(+), 13 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 1092164..3de8a6f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -13,8 +13,6 @@ jacoco { android { compileSdk = AndroidSdk.compileSdkVersion - buildToolsVersion = "30.0.3" - android.buildFeatures.dataBinding = true android.buildFeatures.viewBinding = true diff --git a/build.gradle.kts b/build.gradle.kts index 90073ec..2d20467 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -16,6 +16,7 @@ allprojects { google() mavenCentral() maven(url = "https://jitpack.io") + maven("https://oss.sonatype.org/content/repositories/snapshots") } apply(plugin = BuildPlugins.dokkaPlugin) @@ -35,12 +36,11 @@ allprojects { buildscript { val kotlinVersion by extra("1.5.21") val jacocoVersion by extra("0.2") - val mvnPublishVersion by extra("0.16.0") + val nexusPublishVersion by extra("1.1.0") dependencies { classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion") classpath("com.hiya:jacoco-android:$jacocoVersion") - classpath("com.vanniktech:gradle-maven-publish-plugin:$mvnPublishVersion") } } diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index 4a26b45..4a101c1 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -64,6 +64,8 @@ object BuildPlugins { const val gradleVersionsPlugin = "com.github.ben-manes.versions" const val jacocoAndroid = "com.hiya.jacoco-android" const val mvnPublishPlugin = "com.vanniktech.maven.publish" + const val mavenPublish = "maven-publish" + const val signing = "signing" } object Libraries { diff --git a/daraja/build.gradle.kts b/daraja/build.gradle.kts index d236282..14bb3de 100644 --- a/daraja/build.gradle.kts +++ b/daraja/build.gradle.kts @@ -4,7 +4,8 @@ plugins { id(BuildPlugins.dagger) id(BuildPlugins.kapt) id(BuildPlugins.jacocoAndroid) - id(BuildPlugins.mvnPublishPlugin) + id(BuildPlugins.mavenPublish) + id(BuildPlugins.signing) } jacoco { @@ -41,12 +42,6 @@ android { jvmTarget = "1.8" } - mavenPublish { - sonatypeHost = com.vanniktech.maven.publish.SonatypeHost.S01 - releaseSigningEnabled = true - androidVariantToPublish = "release" - } - buildTypes { getByName("debug") { } @@ -58,7 +53,6 @@ android { dependencies { implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar")))) - implementation(Libraries.kotlinStdLib) implementation(Libraries.coreKtx) // Network - Retrofit, OKHTTP, chucker @@ -73,4 +67,129 @@ dependencies { implementation(Libraries.timber) testImplementation(TestLibraries.jUnit) +} + +tasks { + val sourceFiles = android.sourceSets.getByName("main").java.srcDirs + + register("withJavadoc") { + isFailOnError = false + dependsOn(android.libraryVariants.toList().last().javaCompileProvider) + + if (! project.plugins.hasPlugin("org.jetbrains.kotlin.android")) { + setSource(sourceFiles) + } + android.bootClasspath.forEach { classpath += project.fileTree(it) } + android.libraryVariants.forEach { variant -> + variant.javaCompileProvider.get().classpath.files.forEach { file -> + classpath += project.fileTree(file) + } + } + exclude("**/internal/*") + val options = options as StandardJavadocDocletOptions + options.links("https://developer.android.com/reference") + options.links("https://docs.oracle.com/javase/8/docs/api/") + + // Workaround for the following error when running on on JDK 9+ + // "The code being documented uses modules but the packages defined in ... are in the unnamed module." + if (JavaVersion.current() >= JavaVersion.VERSION_1_9) { + options.addStringOption("-release", "8") + } + } + + register("withJavadocJar") { + archiveClassifier.set("javadoc") + dependsOn(named("withJavadoc")) + val destination = named("withJavadoc").get().destinationDir + from(destination) + } + + register("withSourcesJar") { + archiveClassifier.set("sources") + from(sourceFiles) + } +} + +afterEvaluate { + fun Project.get(name: String, def: String = "$name not found") = + properties[name]?.toString() ?: System.getenv(name) ?: def + + fun Project.getRepositoryUrl(): java.net.URI { + val isReleaseBuild = !get("POM_VERSION_NAME").contains("SNAPSHOT") + val releaseRepoUrl = get( + "RELEASE_REPOSITORY_URL", + "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + ) + val snapshotRepoUrl = get( + "SNAPSHOT_REPOSITORY_URL", + "https://oss.sonatype.org/content/repositories/snapshots/" + ) + return uri(if (isReleaseBuild) releaseRepoUrl else snapshotRepoUrl) + } + + publishing { + publications { + val props = project.properties + repositories { + maven { + url = getRepositoryUrl() + credentials { + username = project.get("ossUsername") + password = project.get("ossPassword") + } + } + } + val publicationName = props["POM_NAME"]?.toString() ?: "publication" + create(publicationName) { + from(project.components["release"]) + artifact(tasks.named("withJavadocJar")) + artifact(tasks.named("withSourcesJar")) + + pom { + groupId = project.get("GROUP") + artifactId = project.get("POM_ARTIFACT_ID") + version = project.get("VERSION_NAME") + + name.set(project.get("POM_NAME")) + description.set(project.get("POM_DESCRIPTION")) + url.set(project.get("POM_URL")) + packaging = project.get("POM_PACKAGING") + + scm { + url.set(project.get("POM_SCM_URL")) + connection.set(project.get("POM_SCM_CONNECTION")) + developerConnection.set(project.get("POM_SCM_DEV_CONNECTION")) + } + + organization { + name.set(project.get("POM_DEVELOPER_NAME")) + url.set(project.get("POM_DEVELOPER_URL")) + } + + developers { + developer { + id.set(project.get("POM_DEVELOPER_ID")) + name.set(project.get("POM_DEVELOPER_NAME")) + } + } + + licenses { + license { + name.set(project.get("POM_LICENCE_NAME")) + url.set(project.get("POM_LICENCE_URL")) + distribution.set(project.get("POM_LICENCE_DIST")) + } + } + } + } + + signing { + val signingKeyId = project.get("signingKeyId") + val signingKeyPassword = project.get("signingKeyPassword") + val signingKey = project.get("signingKey") + useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassword) + sign(publishing.publications.getByName(publicationName)) + } + } + } } \ No newline at end of file diff --git a/daraja/gradle.properties b/daraja/gradle.properties index 0d44c4c..c97a8c2 100644 --- a/daraja/gradle.properties +++ b/daraja/gradle.properties @@ -1,6 +1,7 @@ GROUP=com.androidstudy.daraja POM_ARTIFACT_ID=daraja VERSION_NAME=2.0.0 +POM_PACKAGING=aar POM_NAME=daraja POM_DESCRIPTION=Android MPESA SDK Library to provide smooth MPESA Experience in Android - Dubbed Daraja diff --git a/settings.gradle.kts b/settings.gradle.kts index 5694b2a..1450b11 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,7 +15,6 @@ pluginManagement { resolutionStrategy { eachPlugin { when (requested.id.id) { - "com.android.application", "com.android.library" -> useModule("com.android.tools.build:gradle:7.2.1") "com.google.firebase.crashlytics" -> useModule("com.google.firebase:firebase-crashlytics-gradle:2.1.0") } } From 3dc16b530247ad1fad3b96c50c648d8376c55815 Mon Sep 17 00:00:00 2001 From: Juma Allan Date: Tue, 21 Jun 2022 01:38:15 +0300 Subject: [PATCH 3/3] fix release repo url --- daraja/build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/daraja/build.gradle.kts b/daraja/build.gradle.kts index 14bb3de..bc2b8f9 100644 --- a/daraja/build.gradle.kts +++ b/daraja/build.gradle.kts @@ -118,11 +118,11 @@ afterEvaluate { val isReleaseBuild = !get("POM_VERSION_NAME").contains("SNAPSHOT") val releaseRepoUrl = get( "RELEASE_REPOSITORY_URL", - "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" ) val snapshotRepoUrl = get( "SNAPSHOT_REPOSITORY_URL", - "https://oss.sonatype.org/content/repositories/snapshots/" + "https://s01.oss.sonatype.org/content/repositories/snapshots/" ) return uri(if (isReleaseBuild) releaseRepoUrl else snapshotRepoUrl) }