Skip to content

Commit

Permalink
updated release plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
jumaallan committed Feb 16, 2023
1 parent 980544b commit 673f668
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 126 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
id(BuildPlugins.kotlinAndroid) apply false
id(BuildPlugins.dokkaPlugin) version Versions.dokka
id(BuildPlugins.gradleVersionsPlugin) version Versions.gradleVersionsPlugin
id(BuildPlugins.mvnPublishPlugin) version Versions.mvnPublishPlugin apply false
}

allprojects {
Expand Down Expand Up @@ -36,7 +37,6 @@ allprojects {
buildscript {
val kotlinVersion by extra("1.6.21")
val jacocoVersion by extra("0.2")
val nexusPublishVersion by extra("1.1.0")

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
object Versions {

const val mvnPublishPlugin = "0.24.0"

// Material and androidX
const val material = "1.9.0-alpha01"
const val constraintLayout = "2.1.4"
Expand Down Expand Up @@ -64,8 +66,6 @@ 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
130 changes: 7 additions & 123 deletions daraja/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id(BuildPlugins.androidLibrary)
id(BuildPlugins.kotlinAndroid)
id(BuildPlugins.dagger)
id(BuildPlugins.kapt)
id(BuildPlugins.jacocoAndroid)
id(BuildPlugins.mavenPublish)
id(BuildPlugins.signing)
id(BuildPlugins.mvnPublishPlugin)
}

jacoco {
Expand Down Expand Up @@ -70,127 +71,10 @@ dependencies {
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")
}
}
mavenPublishing {

register<Jar>("withJavadocJar") {
archiveClassifier.set("javadoc")
dependsOn(named("withJavadoc"))
val destination = named<Javadoc>("withJavadoc").get().destinationDir
from(destination)
}
// publish to https://s01.oss.sonatype.org
publishToMavenCentral(SonatypeHost.S01, true)

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))
}
}
}
signAllPublications()
}

0 comments on commit 673f668

Please sign in to comment.