Skip to content

Commit

Permalink
Migrating to modern maven publish plugin (#30)
Browse files Browse the repository at this point in the history
* Migrating to modern maven publish plugin

* Updating workflow
  • Loading branch information
stigi authored Oct 11, 2024
1 parent 2c141d2 commit 358b773
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 133 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/release-gradle-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ on:
release:
types: [ created ]

env:
ORG_GRADLE_PROJECT_signingInMemoryKey: ${{ secrets.SIGNING_KEY }}
ORG_GRADLE_PROJECT_signingInMemoryKeyId: ${{ secrets.SIGNING_KEYID }}
ORG_GRADLE_PROJECT_signingInMemoryKeyPassword: ${{ secrets.SIGNING_PASSWORD }}
ORG_GRADLE_PROJECT_mavenCentralUsername: ${{ secrets.NEXUS_USERNAME }}
ORG_GRADLE_PROJECT_mavenCentralPassword: ${{ secrets.NEXUS_PASSWORD }}

jobs:
publish:
runs-on: ubuntu-latest
Expand All @@ -22,16 +29,6 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Setup Keyring
id: keyring
env:
KEYRING_FILE: ${{ runner.temp }}/publish-keyring.gpg
DATA: ${{ secrets.SIGNING_KEYRING }}
run: |
echo "Creating Keyring file at $KEYRING_FILE"
echo $DATA | base64 -di > $KEYRING_FILE
echo "keyringFile=$KEYRING_FILE" >> "$GITHUB_OUTPUT"
- name: Sanity Check
run: |
./gradlew \
Expand All @@ -41,17 +38,11 @@ jobs:
- name: Publish to Maven Local
run: |
./gradlew \
-Psigning.keyId="${{ secrets.SIGNING_KEYID }}" \
-Psigning.password="${{ secrets.SIGNING_PASSWORD }}" \
-Psigning.secretKeyRingFile="${{ steps.keyring.outputs.keyringFile }}" \
sdk:publishToMavenLocal sdk-compose:publishToMavenLocal
- name: Publish to Maven
run: |
./gradlew \
-Psigning.keyId="${{ secrets.SIGNING_KEYID }}" \
-Psigning.password="${{ secrets.SIGNING_PASSWORD }}" \
-Psigning.secretKeyRingFile="${{ steps.keyring.outputs.keyringFile }}" \
-PNEXUS_USERNAME="${{ secrets.NEXUS_USERNAME }}" \
-PNEXUS_PASSWORD="${{ secrets.NEXUS_PASSWORD }}" \
sdk:publish sdk-compose:publish
115 changes: 24 additions & 91 deletions gradle-mvn-push.gradle
Original file line number Diff line number Diff line change
@@ -1,103 +1,36 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

version = '3.0.0'
group = 'com.magicbell'
mavenPublishing {
coordinates("com.magicbell", null, "3.0.0")

def isReleaseBuild() {
return version.contains("SNAPSHOT") == false
}
// Configure code signing constants according to
// https://vanniktech.github.io/gradle-maven-publish-plugin/central/#secrets
signAllPublications()

def getReleaseRepositoryUrl() {
return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
}
pom {
name = "MagicBell"
description = 'Official MagicBell SDK for Android. The notification inbox for your product.'
url = 'https://www.magicbell.com/'

def getSnapshotRepositoryUrl() {
return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: "https://s01.oss.sonatype.org/content/repositories/snapshots/"
}

def getRepositoryUsername() {
return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : ""
}

def getRepositoryPassword() {
return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : ""
}

def getGpgKey() {
return hasProperty('SIGNING_KEY') ? SIGNING_KEY : ""
}

def getGpgPassphrase() {
return hasProperty('PASSPHRASE') ? PASSPHRASE : ""
}

def configurePom(pom) {
pom.name = 'MagicBell'
pom.description = 'Official MagicBell SDK for Android. The notification inbox for your product.'
pom.url = 'https://www.magicbell.com/'

pom.scm {
url = 'https://github.com/magicbell/magicbell-android.git'
connection = 'scm:[email protected]:magicbell/magicbell-android.git'
developerConnection = 'scm:[email protected]:magicbell/magicbell-android.git'
}

pom.licenses {
license {
name = 'Custom'
url = 'https://github.com/magicbell/magicbell-android/blob/main/LICENSE'
distribution = 'repo'
}
}

pom.developers {
developer {
id = 'magicbell'
name = 'MagicBell'
scm {
url = 'https://github.com/magicbell/magicbell-android.git'
connection = 'scm:[email protected]:magicbell/magicbell-android.git'
developerConnection = 'scm:[email protected]:magicbell/magicbell-android.git'
}
}
}

afterEvaluate { project ->
publishing {

repositories {
maven {
def releasesRepoUrl = getReleaseRepositoryUrl()
def snapshotsRepoUrl = getSnapshotRepositoryUrl()
url = isReleaseBuild() ? releasesRepoUrl : snapshotsRepoUrl

credentials(PasswordCredentials) {
username = getRepositoryUsername()
password = getRepositoryPassword()
}
licenses {
license {
name = 'Custom'
url = 'https://github.com/magicbell/magicbell-android/blob/main/LICENSE'
distribution = 'repo'
}
}
}

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

publishing.publications.all { publication ->
publication.groupId = group
publication.version = version

artifact(javadocJar) // TODO include real documentation

configurePom(publication.pom)
}

signing {
required { isReleaseBuild() }
def gpgKey = getGpgKey()
def gpgPassphrase = getGpgPassphrase()
if (!gpgKey.isEmpty() && !gpgPassphrase.isEmpty()) {
useInMemoryPgpKeys(gpgKey, gpgPassphrase)
developers {
developer {
id = 'magicbell'
name = 'MagicBell'
}
}
sign(publishing.publications)
}
}
}
4 changes: 2 additions & 2 deletions scripts/update-version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const replacements = [
},
{
files: 'gradle-mvn-push.gradle',
from: /version = '\d\.\d\.\d'/g,
to: `version = '${version}'`,
from: /coordinates\("com.magicbell", null, "\d\.\d\.\d"\)/g,
to: `coordinates("com.magicbell", null, "${version}")`,
}
]

Expand Down
19 changes: 7 additions & 12 deletions sdk-compose/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'com.vanniktech.maven.publish' version '0.29.0'
}

apply from: '../gradle-mvn-push.gradle'

android {
compileSdk 31

Expand Down Expand Up @@ -46,16 +47,10 @@ dependencies {
implementation project(':sdk')
}

apply from: '../gradle-mvn-push.gradle'
afterEvaluate { project ->
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release

artifactId = 'magicbell-sdk-compose'
}
}
mavenPublishing {
coordinates(null, "magicbell-sdk-compose", null)
publishToMavenCentral(SonatypeHost.S01)
}
}
19 changes: 7 additions & 12 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import com.vanniktech.maven.publish.SonatypeHost

plugins {
id 'com.android.library'
id 'kotlin-android'
id 'kotlinx-serialization'
id 'de.mannodermaus.android-junit5'
id 'com.vanniktech.maven.publish' version '0.29.0'
}

apply from: '../gradle-mvn-push.gradle'

android {
compileSdk 31

Expand Down Expand Up @@ -60,16 +61,10 @@ dependencies {
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.0'
}

apply from: '../gradle-mvn-push.gradle'
afterEvaluate { project ->
publishing {
publications {
// Creates a Maven publication called "release".
release(MavenPublication) {
// Applies the component for the release build variant.
from components.release

artifactId = 'magicbell-sdk'
}
}
mavenPublishing {
coordinates(null, "magicbell-sdk", null)
publishToMavenCentral(SonatypeHost.S01)
}
}

0 comments on commit 358b773

Please sign in to comment.