diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c216c9b..2347c19 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -36,10 +36,12 @@ jobs: - name: Build with Gradle run: ./gradlew build - # The USERNAME and TOKEN need to correspond to the credentials environment variables used in - # the publishing section of your build.gradle - - name: Publish to GitHub Packages - run: ./gradlew publish + - name: Publish package + run: ./gradlew clean build publishSDKPublicationToSonatypeRepository closeAndReleaseSonatypeStagingRepository env: - USERNAME: ${{ github.actor }} - TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_PASSWORD }} + SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }} + SIGNING_KEY: ${{ secrets.SIGNING_KEY }} + SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }} + SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }} diff --git a/PaymentIcons/build.gradle.kts b/PaymentIcons/build.gradle.kts index 8d3097b..9d3b133 100644 --- a/PaymentIcons/build.gradle.kts +++ b/PaymentIcons/build.gradle.kts @@ -1,8 +1,16 @@ plugins { - id("java-library") + id("java") id("org.jetbrains.kotlin.jvm") } +extra.apply { + set("PUBLISH_GROUP_ID", "com.cashfree.pg") + set("PUBLISH_ARTIFACT_ID", "icons") + set("PUBLISH_VERSION", "1.0.0") +} + +apply(from = "${rootProject.projectDir}/scripts/publish-module.gradle") + java { sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 diff --git a/app/build.gradle.kts b/app/build.gradle.kts index a2ee257..e6b4713 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -45,6 +45,7 @@ dependencies { implementation("androidx.appcompat:appcompat:1.6.1") implementation("com.google.android.material:material:1.10.0") implementation(project(":PaymentIcons")) + //implementation("com.cashfree.pg:icons:1.0.0") testImplementation("junit:junit:4.13.2") androidTestImplementation("androidx.test.ext:junit:1.1.5") androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") diff --git a/build.gradle.kts b/build.gradle.kts index 0cdab47..cc3500e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,4 +3,15 @@ plugins { id("com.android.application") version "8.1.1" apply false id("org.jetbrains.kotlin.android") version "1.9.0" apply false id("org.jetbrains.kotlin.jvm") version "1.9.0" apply false + id("io.github.gradle-nexus.publish-plugin") version "1.1.0" apply true +} + +nexusPublishing { + repositories { + sonatype { + stagingProfileId.set(System.getenv("SONATYPE_STAGING_PROFILE_ID")) + username.set(System.getenv("MAVEN_USERNAME")) + password.set(System.getenv("MAVEN_PASSWORD")) + } + } } \ No newline at end of file diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..08acb24 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,119 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +tasks.register('sourcesJar', Jar) { + archiveClassifier.set('sources') + if (project.plugins.findPlugin("com.android.library")) { + // For Android libraries + from android.sourceSets.main.java.srcDirs + from android.sourceSets.main.kotlin.srcDirs + } else { + // For pure Kotlin libraries, in case you have them + from sourceSets.main.java.srcDirs + from sourceSets.main.kotlin.srcDirs + } +} + +tasks.register('packageJavadoc', Jar) { + archiveClassifier.set('javadoc') + from javadoc.destinationDir +} + +artifacts { + archives sourcesJar + archives packageJavadoc +} + +group = PUBLISH_GROUP_ID +version = PUBLISH_VERSION + +afterEvaluate { + publishing { + publications { + SDK(MavenPublication) { + // The coordinates of the library, being set from variables that + // we'll set up later + groupId PUBLISH_GROUP_ID + artifactId PUBLISH_ARTIFACT_ID + version PUBLISH_VERSION + + if (project.plugins.findPlugin("com.android.library")) { + from components.release + } else { + from components.java + } + + artifact sourcesJar + artifact packageJavadoc + + // Mostly self-explanatory metadata + pom { + name = PUBLISH_ARTIFACT_ID + description = 'Cashfree Payments, Payment Icon library' + url = 'https://github.com/cashfree/payments-icons-java' + licenses { + license { + name = 'MIT License' + } + } + developers { + developer { + id = 'developers.cashfree' + name = 'Cashfree Payments' + email = 'developers@cashfree.com' + } + } + + scm { + connection = 'scm:git:github.com:cashfree/payments-icons-java.git' + developerConnection = 'scm:git:ssh://github.com:cashfree/payments-icons-java.git' + url = 'https://github.com/cashfree/payments-icons-java' + } + + withXml { + Node pomNode = asNode() + pomNode.dependencies.'*'.each() { + it.parent().remove(it) + } + pomNode.remove(pomNode.dependencies) + def dependenciesNode = asNode().appendNode('dependencies') + // Iterate over the api dependencies (we don't want the test ones), adding a node for each + configurations.implementation.allDependencies.each { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + dependencyNode.appendNode('scope', "compile") + } + configurations.api.allDependencies.each { + def dependencyNode = dependenciesNode.appendNode('dependency') + dependencyNode.appendNode('groupId', it.group) + dependencyNode.appendNode('artifactId', it.name) + dependencyNode.appendNode('version', it.version) + dependencyNode.appendNode('scope', "compile") + } + } + } + } + } + repositories { + maven { + name = "OSSRH" + url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + credentials { + username = System.getenv("MAVEN_USERNAME") + password = System.getenv("MAVEN_PASSWORD") + } + } + } + } +} + +signing { + useInMemoryPgpKeys( + System.getenv("SIGNING_KEY_ID"), + System.getenv("SIGNING_KEY"), + System.getenv("SIGNING_PASSWORD") + ) + sign publishing.publications +} diff --git a/settings.gradle.kts b/settings.gradle.kts index 0fd860f..a119896 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,9 @@ pluginManagement { google() mavenCentral() gradlePluginPortal() + maven { + url = uri("https://plugins.gradle.org/m2/") + } } } dependencyResolutionManagement { @@ -10,6 +13,9 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { + url = uri("https://plugins.gradle.org/m2/") + } } }