Skip to content

Commit

Permalink
Merge pull request #162 from SwedbankPay/feature/maven-central
Browse files Browse the repository at this point in the history
Migrate to Maven Central distribution
  • Loading branch information
IhmeHippi authored Feb 11, 2021
2 parents 40faa78 + e16ca41 commit ab5ca89
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 60 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/upload-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
with:
java-version: 1.8
- name: Build with Gradle
run: ./gradlew bintrayUpload
run: ./gradlew publishReleasePublicationToCentralRepository
env:
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
BINTRAY_KEY: ${{ secrets.BINTRAY_KEY }}
BINTRAY_REPO: swedbank-pay-sdk-android
BINTRAY_PKG: swedbank-pay-sdk-android
BINTRAY_ORG: swedbankpay
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
OSSRH_USER: ${{ secrets.OSSRH_USER }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ buildscript {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.jetbrains.dokka:dokka-gradle-plugin:0.10.1'
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5'
classpath 'org.ajoberstar.grgit:grgit-gradle:4.1.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down
143 changes: 89 additions & 54 deletions sdk/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,30 @@ apply plugin: 'org.jetbrains.dokka'

apply plugin: 'maven-publish'

apply plugin: 'signing'

apply plugin: 'org.ajoberstar.grgit'

apply plugin: 'com.jfrog.bintray'

// Support for Github Actions based CI: create named versions from Github releases
static def readGithubReleaseEvent() {
def isRelease = System.getenv('GITHUB_EVENT_NAME') == 'release'
def path = isRelease ? System.getenv('GITHUB_EVENT_PATH') : null
def file = path ? new File(path) : null
def text = file?.text
return text ? new JsonSlurper().parseText(text) : null
}

static def getSnapshotVersionName(grgit) {
return "${grgit.describe(tags: true)}${grgit.status().isClean() ? '' : '-dirty'}-SNAPSHOT"
}

def githubReleaseEvent = readGithubReleaseEvent()

def versionName = githubReleaseEvent?.release?.tag_name
?: (grgit ? getSnapshotVersionName(grgit) : 'local')

android {
compileSdkVersion 29
defaultConfig {
Expand All @@ -20,6 +42,7 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles 'proguard-rules.pro'
testInstrumentationRunnerArguments clearPackageData: 'true'
buildConfigField('String', 'SDK_VERSION', "\"$versionName\"")
}
sourceSets {
def testCommon = 'src/testCommon/java'
Expand All @@ -41,15 +64,6 @@ android {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
buildTypes {
release {
def version = readGithubReleaseEvent()?.release?.tag_name ?: 'snapshot'
buildConfigField('String', 'SDK_VERSION', "\"$version\"")
}
debug {
buildConfigField('String', 'SDK_VERSION', '"debug"')
}
}
dokka {
configuration {
sourceLink {
Expand Down Expand Up @@ -87,10 +101,10 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'

implementation 'com.google.android.gms:play-services-base:17.5.0'
implementation 'com.google.android.gms:play-services-basement:17.5.0'
implementation 'com.google.android.gms:play-services-base:17.6.0'
implementation 'com.google.android.gms:play-services-basement:17.6.0'

def okhttp_version = '4.9.0'
def okhttp_version = '4.9.1'
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
testImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
androidTestImplementation "com.squareup.okhttp3:mockwebserver:$okhttp_version"
Expand Down Expand Up @@ -128,68 +142,89 @@ task dokkaGithub(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputDirectory ="$projectDir/dokka_github"
}

task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaTask) {
outputFormat = 'javadoc'
outputDirectory = "$buildDir/javadoc"
}

task sourceJar(type: Jar) {
from android.sourceSets.main.java.srcDirs
archiveClassifier.set("sources")
archiveClassifier.set('sources')
}

static def readGithubReleaseEvent() {
def isRelease = System.getenv('GITHUB_EVENT_NAME') == 'release'
def path = isRelease ? System.getenv('GITHUB_EVENT_PATH') : null
def file = path ? new File(path) : null
def text = file?.text
return text ? new JsonSlurper().parseText(text) : null
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
from "$buildDir/javadoc"
archiveClassifier.set('javadoc')
}

afterEvaluate {
// Support for Github Actions based CI: create named versions from Github releases
def githubRelease = readGithubReleaseEvent()?.release
def githubTag = githubRelease?.tag_name


afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release
artifact(sourceJar)
artifact sourceJar
artifact javadocJar

// If you fork this library, you should use your own groupId and artifactId here
groupId = 'com.swedbankpay.mobilesdk'
artifactId = 'mobilesdk'
version = githubTag ?: 'local'
version = versionName

pom {
name = "$groupId:$artifactId"
description = 'A library for integrating Swedbank Pay payments into an Android application'
url = 'https://developer.swedbankpay.com/modules-sdks/mobile-sdk/'

licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}

developers {
developer {
name = 'Pertti Kröger'
email = 'pertti@qvik.fi'
organization = 'Qvik'
organizationUrl = "https://qvik.com/"
}
}

scm {
connection = 'scm:git:git://github.com/SwedbankPay/swedbank-pay-sdk-android.git'
developerConnection = 'scm:git:ssh://github.com:SwedbankPay/swedbank-pay-sdk-android.git'
url = 'https://github.com/SwedbankPay/swedbank-pay-sdk-android'
}
}
}
}
}

// The rest of this is specific to Bintray;
// you may not need this part in a fork if you always build everything locally.
// Environment variables are set by the Github Actions workflow.
if (githubTag) {
def bintrayUser = System.getenv('BINTRAY_USER')
def bintrayKey = System.getenv('BINTRAY_KEY')
def bintrayRepo = System.getenv('BINTRAY_REPO')
def bintrayPackage = System.getenv('BINTRAY_PKG')
def bintrayOrganization = System.getenv('BINTRAY_ORG')
if (bintrayUser && bintrayKey && bintrayRepo && bintrayPackage) {
def publishedAt = githubRelease.published_at
def releaseDate = publishedAt ? Instant.parse(publishedAt).toDate() : null

bintray {
user = bintrayUser
key = bintrayKey
publications = ['release']
publish = false
pkg {
repo = bintrayRepo
name = bintrayPackage
userOrg = bintrayOrganization
version {
name = githubTag
desc = githubRelease.body
released = releaseDate
vcsTag = githubTag
}
repositories {
maven {
name = "Central"

def snapshotUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
def stagingUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
url = githubReleaseEvent ? stagingUrl : snapshotUrl

credentials {
username = System.getenv('OSSRH_USER')
password = System.getenv('OSSRH_PASSWORD')
}
}
}
}

signing {
def signingKey = System.getenv('SIGNING_KEY')
def signingKeyPassword = System.getenv('SIGNING_KEY_PASSWORD')
if (signingKey && signingKeyPassword) {
def signingKeyId = System.getenv('SIGNING_KEY_ID')
useInMemoryPgpKeys(signingKeyId, signingKey, signingKeyPassword)
sign publishing.publications.release
}
}
}

0 comments on commit ab5ca89

Please sign in to comment.