Skip to content

Commit

Permalink
Add scripts to deploy to maven central.
Browse files Browse the repository at this point in the history
  • Loading branch information
bffcorreia committed Nov 30, 2022
1 parent 0089452 commit 4ec1ef8
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ plugins {
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
id 'org.jetbrains.kotlin.jvm' version '1.7.20' apply false
id 'com.google.devtools.ksp' version '1.7.20-1.0.7' apply false
}
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
}

apply from: "${rootDir}/scripts/publish-root.gradle"
8 changes: 8 additions & 0 deletions peanuts/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ plugins {
id 'org.jetbrains.kotlin.jvm'
}

ext {
PUBLISH_GROUP_ID = 'dev.pinkroom'
PUBLISH_VERSION = '0.0.1'
PUBLISH_ARTIFACT_ID = 'peanuts'
}

apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand Down
71 changes: 71 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
}
}

artifacts {
archives androidSourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
}

artifact androidSourcesJar

pom {
name = PUBLISH_ARTIFACT_ID
description = 'Updating your UI state is now peanuts!'
url = 'https://github.com/pink-room/peanuts'
licenses {
license {
name = 'Apache-2.0 License'
url = 'https://github.com/pink-room/peanuts/blob/main/LICENSE'
}
}
developers {
developer {
id = 'bffcorreia'
name = 'Bruno Correia'
email = '[email protected]'
}
}

scm {
connection = 'scm:git:github.com/pink-room/peanuts.git'
developerConnection = 'scm:git:ssh://github.com/pink-room/peanuts.git'
url = 'https://github.com/pink-room/peanuts/tree/main'
}
}
}
}
}
}

signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)
sign publishing.publications
}
36 changes: 36 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''
ext["snapshot"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// Read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// Use system environment variables
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
ext["snapshot"] = System.getenv('SNAPSHOT')
}

nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

0 comments on commit 4ec1ef8

Please sign in to comment.