Skip to content
This repository was archived by the owner on Mar 8, 2024. It is now read-only.

Commit dcaf909

Browse files
Update gradle & CI to publish to Maven Central
1 parent 93be2e1 commit dcaf909

File tree

3 files changed

+132
-15
lines changed

3 files changed

+132
-15
lines changed

.circleci/config.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ commands:
2626
command: |
2727
echo $GOOGLE_SERVICES | base64 -di > app/google-services.json
2828
name: Download google-services.json
29+
load_gpg_key:
30+
description: Loads the Base64 encoded GPG key into a file
31+
steps:
32+
- run: echo $GPG_KEY_CONTENTS | base64 -d > $SIGNING_SECRET_KEY_RING_FILE
2933

3034
jobs:
3135
nightly_check:
@@ -156,6 +160,7 @@ jobs:
156160
steps:
157161
- checkout
158162
- download_google_services
163+
- load_gpg_key
159164
- checksum
160165
- restore_cache:
161166
key: gradle-{{ arch }}-{{ checksum "/tmp/checksum.txt" }}
@@ -167,9 +172,11 @@ jobs:
167172
- ~/.gradle
168173
key: gradle-{{ arch }}-{{ checksum "/tmp/checksum.txt" }}
169174
- run:
170-
name: Assemble library and distibute
175+
name: Assemble library and distribute
171176
command: |
172-
eval "$COMMAND_CREATE_LIB_DIST_RELEASE"
177+
./gradlew kbarcode:assembleRelease
178+
./gradlew kbarcode:androidSourcesJar
179+
./gradlew kbarcode:publishReleasePublicationToMavenCentralRepository
173180
- store_artifacts:
174181
path: kbarcode/build/outputs/aar
175182
destination: apk

kbarcode/build.gradle

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,33 +77,29 @@ dependencies {
7777
}
7878

7979
ext {
80-
bintrayRepo = 'maven'
81-
bintrayName = 'KBarcode'
80+
publishGroupId = 'uk.co.brightec.kbarcode'
81+
publishArtifactId = 'kbarcode'
82+
publishVersion = '1.2.2'
8283

83-
publishedGroupId = 'uk.co.brightec.kbarcode'
8484
libraryName = 'KBarcode'
85-
artifact = 'kbarcode'
86-
8785
libraryDescription = 'A library to help implement barcode scanning'
88-
89-
siteUrl = 'https://github.com/brightec/KBarcode'
90-
gitUrl = 'https://github.com/brightec/KBarcode.git'
91-
92-
libraryVersion = '1.2.2'
86+
libraryUrl = 'https://github.com/brightec/KBarcode'
9387

9488
developerId = 'alistairsykes'
9589
developerName = 'Alistair Sykes'
9690
developerEmail = 'alistair@brightec.co.uk'
9791

92+
scmConnection = 'scm:git:github.com/brightec/KBarcode.git'
93+
scmDeveloperConnection = 'scm:git:ssh://github.com/brightec/KBarcode.git'
94+
scmUrl = 'https://github.com/brightec/KBarcode/tree/master'
95+
9896
licenseName = 'MIT'
9997
licenseUrl = 'https://github.com/brightec/KBarcode/blob/master/LICENSE'
100-
allLicenses = ["MIT"]
10198
}
10299

103100
// Turn off javadocs as currently it doesn't work with kotlin
104101
tasks.withType(Javadoc).all {
105102
enabled = false
106103
}
107104

108-
apply from: 'https://raw.githubusercontent.com/brightec/JCenter/master/installv1.gradle'
109-
apply from: 'https://raw.githubusercontent.com/brightec/JCenter/master/bintrayv1.gradle'
105+
apply from: "${rootProject.projectDir}/scripts/publish-mavencentral.gradle"
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// The contents of this file is from https://getstream.io/blog/publishing-libraries-to-mavencentral-2021/
2+
apply plugin: 'maven-publish'
3+
apply plugin: 'signing'
4+
5+
task androidSourcesJar(type: Jar) {
6+
archiveClassifier.set('sources')
7+
if (project.plugins.findPlugin("com.android.library")) {
8+
// For Android libraries
9+
from android.sourceSets.main.java.srcDirs
10+
from android.sourceSets.main.kotlin.srcDirs
11+
} else {
12+
// For pure Kotlin libraries, in case you have them
13+
from sourceSets.main.java.srcDirs
14+
from sourceSets.main.kotlin.srcDirs
15+
}
16+
}
17+
18+
artifacts {
19+
archives androidSourcesJar
20+
}
21+
22+
group = publishGroupId
23+
version = publishVersion
24+
25+
ext["signing.keyId"] = ''
26+
ext["signing.password"] = ''
27+
ext["signing.secretKeyRingFile"] = ''
28+
ext["ossrhUsername"] = ''
29+
ext["ossrhPassword"] = ''
30+
ext["sonatypeStagingProfileId"] = ''
31+
32+
File secretPropsFile = project.rootProject.file('local.properties')
33+
if (secretPropsFile.exists()) {
34+
Properties p = new Properties()
35+
new FileInputStream(secretPropsFile).withCloseable { is ->
36+
p.load(is)
37+
}
38+
p.each { name, value ->
39+
ext[name] = value
40+
}
41+
} else {
42+
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
43+
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
44+
ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
45+
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
46+
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
47+
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
48+
}
49+
50+
publishing {
51+
publications {
52+
release(MavenPublication) {
53+
groupId publishGroupId
54+
artifactId publishArtifactId
55+
version publishVersion
56+
57+
if (project.plugins.findPlugin("com.android.library")) {
58+
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")
59+
} else {
60+
artifact("$buildDir/libs/${project.getName()}-${version}.jar")
61+
}
62+
artifact androidSourcesJar
63+
64+
// Mostly self-explanatory metadata
65+
pom {
66+
name = libraryName
67+
description = libraryDescription
68+
url = libraryUrl
69+
licenses {
70+
license {
71+
name = licenseName
72+
url = licenseUrl
73+
}
74+
}
75+
developers {
76+
developer {
77+
id = developerId
78+
name = developerName
79+
email = developerEmail
80+
}
81+
}
82+
scm {
83+
connection = scmConnection
84+
developerConnection = scmDeveloperConnection
85+
url = scmUrl
86+
}
87+
withXml {
88+
def dependenciesNode = asNode().appendNode('dependencies')
89+
90+
project.configurations.implementation.allDependencies.each {
91+
def dependencyNode = dependenciesNode.appendNode('dependency')
92+
dependencyNode.appendNode('groupId', it.group)
93+
dependencyNode.appendNode('artifactId', it.name)
94+
dependencyNode.appendNode('version', it.version)
95+
}
96+
}
97+
}
98+
}
99+
}
100+
repositories {
101+
maven {
102+
name = "mavenCentral"
103+
url = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
104+
credentials {
105+
username ossrhUsername
106+
password ossrhPassword
107+
}
108+
}
109+
}
110+
}
111+
112+
signing {
113+
sign publishing.publications
114+
}

0 commit comments

Comments
 (0)