diff --git a/build.gradle b/build.gradle index 6f464b8..3cb7575 100644 --- a/build.gradle +++ b/build.gradle @@ -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() @@ -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() @@ -31,4 +34,4 @@ allprojects { task clean(type: Delete) { delete rootProject.buildDir -} +} \ No newline at end of file diff --git a/gradle/publish-module.gradle b/gradle/publish-module.gradle new file mode 100644 index 0000000..6adb95a --- /dev/null +++ b/gradle/publish-module.gradle @@ -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 +} diff --git a/gradle/publish-root.gradle b/gradle/publish-root.gradle new file mode 100644 index 0000000..fcb90be --- /dev/null +++ b/gradle/publish-root.gradle @@ -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 + } + } +} diff --git a/gradle/versions.gradle b/gradle/versions.gradle new file mode 100644 index 0000000..be4a3f4 --- /dev/null +++ b/gradle/versions.gradle @@ -0,0 +1,3 @@ +ext['KOTLIN_VERSION'] = "1.8.0" +ext['COROUTINES_VERSION'] = "1.6.4" +ext['MP_PAGING_VERSION'] = "0.6.1" diff --git a/paging/build.gradle.kts b/paging/build.gradle.kts index 957e144..f747d06 100644 --- a/paging/build.gradle.kts +++ b/paging/build.gradle.kts @@ -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() @@ -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().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) - } - } - } - } -} diff --git a/sample/multiplatform-library/build.gradle.kts b/sample/multiplatform-library/build.gradle.kts index 4665c9e..fdbc857 100644 --- a/sample/multiplatform-library/build.gradle.kts +++ b/sample/multiplatform-library/build.gradle.kts @@ -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"