Skip to content

Commit 8879451

Browse files
authored
Merge pull request #4 from thepeerstack/feature/setup-publish-to-maven
Setup publishing artifacts to maven central
2 parents b28b859 + 56e79d4 commit 8879451

File tree

10 files changed

+227
-31
lines changed

10 files changed

+227
-31
lines changed

.github/workflows/android.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Android CI
2+
3+
on:
4+
5+
pull_request:
6+
push:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: set up JDK 11
17+
uses: actions/setup-java@v3
18+
with:
19+
java-version: '11'
20+
distribution: 'temurin'
21+
cache: gradle
22+
23+
- name: Grant execute permission for gradlew
24+
run: chmod +x gradlew
25+
26+
# This will be enabled after the code-quality PR is merged
27+
# - name: Run Ktlint
28+
# uses: lucasnlm/ktlint-action@master
29+
#
30+
# - name: Check code quality
31+
# run: ./gradlew thepeer-android:ktlint
32+
33+
- name: Build thepeer-android library
34+
run: ./gradlew thepeer-android:build
35+
36+
- name: Build Kotlin demo
37+
run: ./gradlew demo-app:build
38+
39+
- name: Build Java demo
40+
run: ./gradlew java-demo:build

.github/workflows/publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
# We'll run this workflow when a new GitHub release is created
6+
types: [released]
7+
8+
jobs:
9+
publish:
10+
name: Release build and publish
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Check out code
14+
uses: actions/checkout@v2
15+
- name: Set up JDK 11
16+
uses: actions/setup-java@v2
17+
with:
18+
distribution: adopt
19+
java-version: 11
20+
21+
# Get publish version from tag
22+
- id: get_version
23+
uses: battila7/get-version-action@v2
24+
- name: Get version from tag
25+
run: echo ${{ teps.get_version.outputs.version-without-v }}
26+
27+
28+
# Builds the release artifacts of the library
29+
- name: Release build
30+
run: ./gradlew :thepeer-android:assembleRelease
31+
32+
# Generates other artifacts (javadocJar is optional)
33+
# - name: Source jar and dokka
34+
# run: ./gradlew androidSourcesJar javadocJar
35+
36+
# Runs upload, and then closes & releases the repository
37+
- name: Publish to MavenCentral
38+
run: ./gradlew publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
39+
env:
40+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
41+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
42+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
43+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
44+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
45+
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
46+
PUBLISH_VERSION: ${{ steps.get_version.outputs.version-without-v }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@
1212
/captures
1313
.externalNativeBuild
1414
.cxx
15-
local.properties
1615
/.idea/*

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Thepeer official Android SDK
22

3+
![CI](https://github.com/thepeerstack/thepeer-android/actions/workflows/android.yml/badge.svg)
4+
35
Thepeer Android SDK gives one integration access to all fintech businesses on your Android App
46

57

build.gradle

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ buildscript {
66
mavenCentral()
77
}
88
dependencies {
9-
classpath "com.android.tools.build:gradle:7.0.4"
9+
classpath "com.android.tools.build:gradle:7.2.1"
1010
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1111
// NOTE: Do not place your application dependencies here; they belong
1212
// in the individual module build.gradle files
1313
}
1414
}
1515

16+
plugins{
17+
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
18+
}
19+
1620
task clean(type: Delete) {
1721
delete rootProject.buildDir
1822
}
@@ -57,4 +61,6 @@ ext {
5761

5862
// Robolectric
5963
robolectricVersion = '4.7.2'
60-
}
64+
}
65+
66+
apply from: "${rootDir}/scripts/publish-root.gradle"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Wed Feb 09 22:24:53 WAT 2022
22
distributionBase=GRADLE_USER_HOME
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
44
distributionPath=wrapper/dists
55
zipStorePath=wrapper/dists
66
zipStoreBase=GRADLE_USER_HOME

local.properties

Lines changed: 0 additions & 8 deletions
This file was deleted.

scripts/publish-module.gradle

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
4+
task androidSourcesJar(type: Jar) {
5+
archiveClassifier.set('sources')
6+
if (project.plugins.findPlugin("com.android.library")) {
7+
// For Android libraries
8+
from android.sourceSets.main.java.srcDirs
9+
from android.sourceSets.main.kotlin.srcDirs
10+
} else {
11+
// For pure Kotlin libraries, in case you have them
12+
from sourceSets.main.java.srcDirs
13+
from sourceSets.main.kotlin.srcDirs
14+
}
15+
}
16+
17+
artifacts {
18+
archives androidSourcesJar
19+
}
20+
21+
group = PUBLISH_GROUP_ID
22+
version = PUBLISH_VERSION
23+
24+
afterEvaluate {
25+
publishing {
26+
publications {
27+
release(MavenPublication) {
28+
// The coordinates of the library, being set from variables that
29+
// we'll set up later
30+
groupId PUBLISH_GROUP_ID
31+
artifactId PUBLISH_ARTIFACT_ID
32+
version PUBLISH_VERSION
33+
34+
// Two artifacts, the `aar` (or `jar`) and the sources
35+
if (project.plugins.findPlugin("com.android.library")) {
36+
from components.release
37+
} else {
38+
from components.java
39+
}
40+
41+
artifact androidSourcesJar
42+
43+
// Mostly self-explanatory metadata
44+
pom {
45+
name = PUBLISH_ARTIFACT_ID
46+
description = 'Thepeer official Android SDK'
47+
url = 'https://github.com/thepeerstack/thepeer-android'
48+
licenses {
49+
license {
50+
name = 'Thepeer License'
51+
url = ''
52+
}
53+
}
54+
developers {
55+
// Add all other devs here...
56+
}
57+
58+
// Version control info - if you're using GitHub, follow the
59+
// format as seen here
60+
scm {
61+
connection = 'scm:git:github.com/thepeerstack/thepeer-android.git'
62+
developerConnection = 'scm:git:ssh://github.com/thepeerstack/thepeer-android.git'
63+
url = 'https://github.com/thepeerstack/thepeer-android/tree/master'
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
signing {
72+
useInMemoryPgpKeys(
73+
rootProject.ext["signingKeyId"],
74+
rootProject.ext["signingKey"],
75+
rootProject.ext["signingPassword"],
76+
)
77+
sign publishing.publications
78+
}

scripts/publish-root.gradle

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Create variables with empty default values
2+
ext["ossrhUsername"] = ''
3+
ext["ossrhPassword"] = ''
4+
ext["sonatypeStagingProfileId"] = ''
5+
ext["signingKeyId"] = ''
6+
ext["signingPassword"] = ''
7+
ext["signingKey"] = ''
8+
ext["publishVersion"] = ''
9+
10+
File secretPropsFile = project.rootProject.file('local.properties')
11+
if (secretPropsFile.exists()) {
12+
// Read local.properties file first if it exists
13+
Properties p = new Properties()
14+
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
15+
p.each { name, value -> ext[name] = value }
16+
} else {
17+
// Use system environment variables
18+
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
19+
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
20+
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
21+
ext["signingKeyId"] = System.getenv('SIGNING_KEY_ID')
22+
ext["signingPassword"] = System.getenv('SIGNING_PASSWORD')
23+
ext["signingKey"] = System.getenv('SIGNING_KEY')
24+
ext["publishVersion"] = System.getenv('PUBLISH_VERSION')
25+
}
26+
27+
28+
// Set up Sonatype repository
29+
nexusPublishing {
30+
repositories {
31+
sonatype {
32+
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
33+
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
34+
stagingProfileId = sonatypeStagingProfileId
35+
username = ossrhUsername
36+
password = ossrhPassword
37+
}
38+
}
39+
}

thepeer-android/build.gradle

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ plugins {
66
id 'maven-publish'
77
}
88

9+
10+
version = "1.0.0"
11+
912
android {
1013
compileSdk 31
1114

@@ -43,10 +46,10 @@ android {
4346

4447
dependencies {
4548

46-
implementation 'androidx.core:core-ktx:1.7.0'
47-
implementation 'androidx.appcompat:appcompat:1.4.1'
48-
implementation 'com.google.android.material:material:1.5.0'
49-
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
49+
implementation 'androidx.core:core-ktx:1.8.0'
50+
implementation 'androidx.appcompat:appcompat:1.4.2'
51+
implementation 'com.google.android.material:material:1.6.1'
52+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
5053

5154
// Kotlin
5255
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutineVersion"
@@ -71,19 +74,10 @@ dependencies {
7174
testImplementation "org.robolectric:shadows-multidex:$robolectricVersion"
7275
}
7376

74-
afterEvaluate {
75-
publishing {
76-
publications {
77-
// Creates a Maven publication called "release".
78-
release(MavenPublication) {
79-
// Applies the component for the release build variant.
80-
from components.release
81-
82-
// You can then customize attributes of the publication as shown below.
83-
groupId = 'io.thepeer'
84-
artifactId = 'thepeer-android'
85-
version = '1.0.0-alpha01.2'
86-
}
87-
}
88-
}
77+
ext {
78+
PUBLISH_GROUP_ID = 'co.thepeer'
79+
PUBLISH_VERSION = publishVersion
80+
PUBLISH_ARTIFACT_ID = 'thepeer-android'
8981
}
82+
83+
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

0 commit comments

Comments
 (0)