Skip to content

Commit 16cab3a

Browse files
authored
Merge pull request #1 from canopas/publish--maven-central
Publish library to maven central
2 parents 9fd93d5 + cad75ae commit 16cab3a

File tree

6 files changed

+162
-1
lines changed

6 files changed

+162
-1
lines changed

.github/workflows/publish.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Publish
2+
on:
3+
push:
4+
tags:
5+
- '*'
6+
7+
jobs:
8+
publish:
9+
name: Release build and publish
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Check out code
13+
uses: actions/checkout@v2
14+
- name: Set up JDK 11
15+
uses: actions/setup-java@v2
16+
with:
17+
distribution: adopt
18+
java-version: 11
19+
20+
- name: Publish to MavenCentral
21+
run: ./gradlew showcase:publishReleasePublicationToSonatypeRepository --max-workers 1 closeAndReleaseSonatypeStagingRepository
22+
env:
23+
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
24+
OSSRH_PASSWORD: ${{ secrets.OSSRH_PASSWORD }}
25+
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
26+
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
27+
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
28+
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}

app/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/build
1+
/build
2+
.idea

build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@ buildscript {
22
ext {
33
compose_version = '1.1.0-beta04'
44
}
5+
56
}// Top-level build file where you can add configuration options common to all sub-projects/modules.
67
plugins {
78
id 'com.android.application' version '7.1.0' apply false
89
id 'com.android.library' version '7.1.0' apply false
910
id 'org.jetbrains.kotlin.android' version '1.6.0' apply false
11+
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
1012
}
1113

14+
apply from: "${rootDir}/scripts/publish-root.gradle"
15+
1216
task clean(type: Delete) {
1317
delete rootProject.buildDir
1418
}

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+
from android.sourceSets.main.java.srcDirs
8+
} else {
9+
from sourceSets.main.java.srcDirs
10+
}
11+
}
12+
13+
artifacts {
14+
archives androidSourcesJar
15+
}
16+
group = PUBLISH_GROUP_ID
17+
version = PUBLISH_VERSION
18+
19+
afterEvaluate {
20+
publishing {
21+
publications {
22+
release(MavenPublication) {
23+
// The coordinates of the library, being set from variables that
24+
// we'll set up later
25+
groupId PUBLISH_GROUP_ID
26+
artifactId PUBLISH_ARTIFACT_ID
27+
version PUBLISH_VERSION
28+
29+
/// Two artifacts, the `aar` (or `jar`) and the sources
30+
if (project.plugins.findPlugin("com.android.library")) {
31+
from components.release
32+
} else {
33+
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
34+
}
35+
36+
artifact androidSourcesJar
37+
38+
// Mostly self-explanatory metadata
39+
pom {
40+
name = PUBLISH_ARTIFACT_ID
41+
description = 'Highlight different features of the app using Jetpack Compose'
42+
url = 'https://github.com/canopas/Intro-showcase-view'
43+
licenses {
44+
license {
45+
name = 'License'
46+
url = 'https://github.com/canopas/Intro-showcase-view/blob/master/License'
47+
}
48+
}
49+
developers {
50+
developer {
51+
id = 'cp-radhika-s'
52+
name = 'Radhika canopas'
53+
email = 'radhika.s@canopas.com'
54+
}
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/canopas/Intro-showcase-view.git'
62+
developerConnection = 'scm:git:ssh://github.com/canopas/Intro-showcase-view.git'
63+
url = 'https://github.com/canopas/Intro-showcase-view.git'
64+
}
65+
}
66+
}
67+
}
68+
}
69+
}
70+
signing {
71+
useInMemoryPgpKeys(
72+
rootProject.ext["signing.keyId"],
73+
rootProject.ext["signing.key"],
74+
rootProject.ext["signing.password"],
75+
)
76+
77+
sign publishing.publications
78+
}

scripts/publish-root.gradle

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

showcase/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ plugins {
33
id 'org.jetbrains.kotlin.android'
44
}
55

6+
ext {
7+
PUBLISH_GROUP_ID = 'com.canopas.intro-showcase-view'
8+
PUBLISH_VERSION = '1.0.2'
9+
PUBLISH_ARTIFACT_ID = 'introshowcaseview'
10+
}
11+
12+
apply from: "${rootDir}/scripts/publish-module.gradle"
13+
614
android {
715
compileSdk 31
816

0 commit comments

Comments
 (0)