Skip to content

Commit 4ec1ef8

Browse files
committed
Add scripts to deploy to maven central.
1 parent 0089452 commit 4ec1ef8

File tree

4 files changed

+119
-1
lines changed

4 files changed

+119
-1
lines changed

build.gradle

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,7 @@ plugins {
1010
id 'org.jetbrains.kotlin.android' version '1.7.20' apply false
1111
id 'org.jetbrains.kotlin.jvm' version '1.7.20' apply false
1212
id 'com.google.devtools.ksp' version '1.7.20-1.0.7' apply false
13-
}
13+
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
14+
}
15+
16+
apply from: "${rootDir}/scripts/publish-root.gradle"

peanuts/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ plugins {
22
id 'org.jetbrains.kotlin.jvm'
33
}
44

5+
ext {
6+
PUBLISH_GROUP_ID = 'dev.pinkroom'
7+
PUBLISH_VERSION = '0.0.1'
8+
PUBLISH_ARTIFACT_ID = 'peanuts'
9+
}
10+
11+
apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
12+
513
java {
614
sourceCompatibility = JavaVersion.VERSION_1_8
715
targetCompatibility = JavaVersion.VERSION_1_8

scripts/publish-module.gradle

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
from android.sourceSets.main.kotlin.srcDirs
9+
}
10+
}
11+
12+
artifacts {
13+
archives androidSourcesJar
14+
}
15+
16+
group = PUBLISH_GROUP_ID
17+
version = PUBLISH_VERSION
18+
19+
afterEvaluate {
20+
publishing {
21+
publications {
22+
release(MavenPublication) {
23+
groupId PUBLISH_GROUP_ID
24+
artifactId PUBLISH_ARTIFACT_ID
25+
version PUBLISH_VERSION
26+
27+
if (project.plugins.findPlugin("com.android.library")) {
28+
from components.release
29+
} else {
30+
from components.java
31+
}
32+
33+
artifact androidSourcesJar
34+
35+
pom {
36+
name = PUBLISH_ARTIFACT_ID
37+
description = 'Updating your UI state is now peanuts!'
38+
url = 'https://github.com/pink-room/peanuts'
39+
licenses {
40+
license {
41+
name = 'Apache-2.0 License'
42+
url = 'https://github.com/pink-room/peanuts/blob/main/LICENSE'
43+
}
44+
}
45+
developers {
46+
developer {
47+
id = 'bffcorreia'
48+
name = 'Bruno Correia'
49+
50+
}
51+
}
52+
53+
scm {
54+
connection = 'scm:git:github.com/pink-room/peanuts.git'
55+
developerConnection = 'scm:git:ssh://github.com/pink-room/peanuts.git'
56+
url = 'https://github.com/pink-room/peanuts/tree/main'
57+
}
58+
}
59+
}
60+
}
61+
}
62+
}
63+
64+
signing {
65+
useInMemoryPgpKeys(
66+
rootProject.ext["signing.keyId"],
67+
rootProject.ext["signing.key"],
68+
rootProject.ext["signing.password"],
69+
)
70+
sign publishing.publications
71+
}

scripts/publish-root.gradle

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

0 commit comments

Comments
 (0)