Skip to content

Commit

Permalink
Merge pull request #77 from jumaallan/feature/maven-central-migration
Browse files Browse the repository at this point in the history
Maven Central Migration
  • Loading branch information
jumaallan authored Jun 20, 2022
2 parents 2e44c73 + 3dc16b5 commit 0c5ea5f
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 18 deletions.
2 changes: 0 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ jacoco {
android {

compileSdk = AndroidSdk.compileSdkVersion
buildToolsVersion = "30.0.3"

android.buildFeatures.dataBinding = true
android.buildFeatures.viewBinding = true

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ allprojects {
google()
mavenCentral()
maven(url = "https://jitpack.io")
maven("https://oss.sonatype.org/content/repositories/snapshots")
}

apply(plugin = BuildPlugins.dokkaPlugin)
Expand All @@ -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")
}
}

Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
135 changes: 127 additions & 8 deletions daraja/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ plugins {
id(BuildPlugins.dagger)
id(BuildPlugins.kapt)
id(BuildPlugins.jacocoAndroid)
id(BuildPlugins.mvnPublishPlugin)
id(BuildPlugins.mavenPublish)
id(BuildPlugins.signing)
}

jacoco {
Expand Down Expand Up @@ -41,12 +42,6 @@ android {
jvmTarget = "1.8"
}

mavenPublish {
sonatypeHost = com.vanniktech.maven.publish.SonatypeHost.S01
releaseSigningEnabled = true
androidVariantToPublish = "release"
}

buildTypes {
getByName("debug") {
}
Expand All @@ -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
Expand All @@ -73,4 +67,129 @@ dependencies {
implementation(Libraries.timber)

testImplementation(TestLibraries.jUnit)
}

tasks {
val sourceFiles = android.sourceSets.getByName("main").java.srcDirs

register<Javadoc>("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<Jar>("withJavadocJar") {
archiveClassifier.set("javadoc")
dependsOn(named("withJavadoc"))
val destination = named<Javadoc>("withJavadoc").get().destinationDir
from(destination)
}

register<Jar>("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://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
)
val snapshotRepoUrl = get(
"SNAPSHOT_REPOSITORY_URL",
"https://s01.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<MavenPublication>(publicationName) {
from(project.components["release"])
artifact(tasks.named<Jar>("withJavadocJar"))
artifact(tasks.named<Jar>("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))
}
}
}
}
1 change: 1 addition & 0 deletions daraja/gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ 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.google.firebase.crashlytics" -> useModule("com.google.firebase:firebase-crashlytics-gradle:2.1.0")
}
}
Expand Down

0 comments on commit 0c5ea5f

Please sign in to comment.