Skip to content

Commit

Permalink
Setup library publishing on sonatype repository
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhamsinghmutualmobile committed Apr 19, 2022
1 parent a9514dd commit dac7998
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
45 changes: 44 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,52 @@ plugins {
id 'com.android.application' version '7.1.2' apply false
id 'com.android.library' version '7.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
// id 'org.jetbrains.kotlin.jvm' version '1.6.10' apply false
id "io.github.gradle-nexus.publish-plugin" version "1.1.0"
}

task clean(type: Delete) {
delete rootProject.buildDir
}

// Initialize publishing/signing extra properties with environmental vars
ext['signing.keyId'] = System.getenv('SIGNING_KEY_ID') ?: ''
ext['signing.password'] = System.getenv('SIGNING_PASSWORD') ?: ''
ext['signing.secretKeyRingFile'] = System.getenv('SIGNING_SECRET_KEY_RING_FILE') ?: ''
ext['ossrhUsername'] = System.getenv('OSSRH_USERNAME') ?: ''
ext['ossrhPassword'] = System.getenv('OSSRH_PASSWORD') ?: ''
// Override with local.properties if available
File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
Properties p = new Properties()
p.load(new FileInputStream(secretPropsFile))
p.each { name, value ->
ext[name] = value
}
}

def pgpKeyContent = System.getenv('PGP_KEY_CONTENTS')
if (pgpKeyContent != null) {
def tmpDir = new File("$rootProject.rootDir/tmp")
mkdir tmpDir
def keyFile = new File("$tmpDir/key.pgp")
keyFile.createNewFile()
def os = keyFile.newDataOutputStream()
os.write(pgpKeyContent.decodeBase64())
os.close()
pgpKeyContent = ''

ext['signing.secretKeyRingFile'] = keyFile.absolutePath
}

nexusPublishing {
repositories {
sonatype {
stagingProfileId = "21d06a31472b96"
nexusUrl.set(uri("https://oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://oss.sonatype.org/content/repositories/snapshots/"))
username = ossrhUsername
password = ossrhPassword
version = ''
}
}
}
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
android.nonTransitiveRClass=true
org.gradle.java.home=/Users/shubhamsingh/Library/Java/JavaVirtualMachines/corretto-11.0.14/Contents/Home
5 changes: 5 additions & 0 deletions publish-helper.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidJavadoc(type: Javadoc) {
if (plugins.hasPlugin('android-library')) {
Expand Down Expand Up @@ -88,4 +89,8 @@ afterEvaluate {
}
}
}
}

signing {
sign publishing.publications
}

0 comments on commit dac7998

Please sign in to comment.