Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
Organizes publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
kuuuurt committed Jan 2, 2023
1 parent fb13688 commit b468365
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 108 deletions.
17 changes: 10 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext {
KOTLIN_VERSION = "1.8.0"
COROUTINES_VERSION = "1.6.4"
MP_PAGING_VERSION = "0.6.1"
}
apply from: "$rootDir/gradle/versions.gradle"

repositories {
mavenLocal()
mavenCentral()
Expand All @@ -20,6 +16,13 @@ buildscript {
}
}

plugins {
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

apply from: "$rootDir/gradle/versions.gradle"
apply from: "${rootDir}/gradle/publish-root.gradle"

allprojects {
repositories {
mavenLocal()
Expand All @@ -31,4 +34,4 @@ allprojects {

task clean(type: Delete) {
delete rootProject.buildDir
}
}
68 changes: 68 additions & 0 deletions gradle/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
apply from: "$rootDir/gradle/versions.gradle"
apply plugin: 'maven-publish'
apply plugin: 'signing'

task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
}

artifacts {
archives javadocJar
}

group = "io.github.kuuuurt"
version = ext["MP_PAGING_VERSION"]

afterEvaluate {
apply from: "$rootDir/gradle/versions.gradle"

publishing {
publications {
withType(MavenPublication) {
if (name.contains("kotlinMultiplatform")) {
artifactId "multiplatform-paging"
} else {
artifactId "multiplatform-paging-$name"
}

groupId group
version version

artifact javadocJar

pom {
name = "multiplatform-paging"
description = "A Kotlin Multiplatform library for pagination on Android and iOS"
url = "https://github.com/kuuuurt/multiplatform-paging"
licenses {
license {
name = "Apache-2.0"
url = "https://www.apache.org/licenses/LICENSE-2.0"
}
}
developers {
developer {
id = 'kuuuurt'
name = 'Kurt Renzo Acosta'
email = "kurt.r.acosta@gmail.com"
}
}
scm {
connection = "https://github.com/kuuuurt/multiplatform-paging.git"
developerConnection = "https://github.com/kuuuurt/multiplatform-paging.git"
url = "https://github.com/kuuuurt/multiplatform-paging"
}
}
}
}
}
}

signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)
sign publishing.publications
}
36 changes: 36 additions & 0 deletions gradle/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Create variables with empty default values
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''

File secretPropsFile = project.rootProject.file('sonatype.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
}
}
}
3 changes: 3 additions & 0 deletions gradle/versions.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ext['KOTLIN_VERSION'] = "1.8.0"
ext['COROUTINES_VERSION'] = "1.6.4"
ext['MP_PAGING_VERSION'] = "0.6.1"
103 changes: 4 additions & 99 deletions paging/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,53 +1,16 @@
import org.gradle.api.publish.maven.internal.artifact.FileBasedMavenArtifact
import java.net.URI
import java.io.FileInputStream
import java.util.Properties

plugins {
id("org.jetbrains.kotlin.multiplatform")
id("maven-publish")
id("signing")
}

val MP_PAGING_VERSION: String by rootProject.extra

val sonatypePropertiesFile = project.rootProject.file("sonatype.properties")
val sonatypeProperties = Properties()
if (sonatypePropertiesFile.exists()) {
sonatypeProperties.load(FileInputStream(sonatypePropertiesFile))

rootProject.extra["signing.keyId"] = sonatypeProperties.getProperty("signing.key_id")
rootProject.extra["signing.password"] = sonatypeProperties.getProperty("signing.password")
rootProject.extra["signing.secretKeyRingFile"] = sonatypeProperties.getProperty("signing.secret_key_ring_file")
}

val artifactName = "multiplatform-paging"
val artifactGroup = "io.github.kuuuurt"
val artifactVersion = MP_PAGING_VERSION

val pomUrl = "https://github.com/kuuuurt/multiplatform-paging"
val pomScmUrl = "https://github.com/kuuuurt/multiplatform-paging.git"
val pomIssueUrl = "https://github.com/kuuuurt/multiplatform-paging/issues"
val pomDesc = "A Kotlin Multiplatform library for pagination on Android and iOS"

val githubRepo = "kuuuurt/multiplatform-paging"
val githubReadme = "README.md"
apply(from = "$rootDir/gradle/versions.gradle")
apply(from = "$rootDir/gradle/publish-module.gradle")

val pomLicenseName = "Apache-2.0"
val pomLicenseUrl = "https://www.apache.org/licenses/LICENSE-2.0"
val pomLicenseDist = "repo"

val pomDeveloperId = "kuuuurt"
val pomDeveloperName = "Kurt Renzo Acosta"
val pomDeveloperEmail = "kurt.r.acosta@gmail.com"
val MP_PAGING_VERSION = ext["MP_PAGING_VERSION"]
val COROUTINES_VERSION = ext["COROUTINES_VERSION"]

val frameworkName = "MultiplatformPaging"

group = artifactGroup
version = artifactVersion

val COROUTINES_VERSION: String by rootProject.extra

kotlin {
ios()
iosSimulatorArm64()
Expand Down Expand Up @@ -75,61 +38,3 @@ kotlin {
iosSimulatorArm64Main.dependsOn(iosMain)
iosSimulatorArm64Test.dependsOn(iosTest)
}

publishing {
repositories {
maven {
name = "mavenCentral"
url = URI("https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/")
credentials {
username = sonatypeProperties.getProperty("ossrh.username")
password = sonatypeProperties.getProperty("ossrh.password")
}
}
}
}

signing {
if (sonatypePropertiesFile.exists()) {
sign(publishing.publications)
}
}

val javadocJar by tasks.registering(Jar::class) {
archiveClassifier.set("javadoc")
}

afterEvaluate {
project.publishing.publications.withType<MavenPublication>().all {
groupId = artifactGroup
artifactId = if (name.contains("kotlinMultiplatform")) {
artifactName
} else {
"$artifactName-$name"
}

// Stub javadoc.jar artifact
artifact(javadocJar.get())

pom.withXml {
asNode().apply {
appendNode("description", pomDesc)
appendNode("name", rootProject.name)
appendNode("url", pomUrl)
appendNode("licenses").appendNode("license").apply {
appendNode("name", pomLicenseName)
appendNode("url", pomLicenseUrl)
appendNode("distribution", pomLicenseDist)
}
appendNode("developers").appendNode("developer").apply {
appendNode("id", pomDeveloperId)
appendNode("name", pomDeveloperName)
appendNode("email", pomDeveloperName)
}
appendNode("scm").apply {
appendNode("url", pomScmUrl)
}
}
}
}
}
6 changes: 4 additions & 2 deletions sample/multiplatform-library/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ plugins {
id("org.jetbrains.kotlin.native.cocoapods")
}

val COROUTINES_VERSION: String by rootProject.extra
val MP_PAGING_VERSION: String by rootProject.extra
apply(from = "$rootDir/gradle/versions.gradle")

val MP_PAGING_VERSION = ext["MP_PAGING_VERSION"]
val COROUTINES_VERSION = ext["COROUTINES_VERSION"]

val iosFrameworkName = "MultiplatformPaging"

Expand Down

0 comments on commit b468365

Please # to comment.