Skip to content

Commit 1f56f2d

Browse files
committed
add maven publish script
1 parent 62edf83 commit 1f56f2d

3 files changed

Lines changed: 95 additions & 2 deletions

File tree

gradle.properties

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ kotlin.code.style=official
2020
# Enables namespacing of each library's R class so that its R class includes only the
2121
# resources declared in the library itself and none from the library's dependencies,
2222
# thereby reducing the size of the R class for that library
23-
android.nonTransitiveRClass=true
23+
android.nonTransitiveRClass=true
24+
25+
PUBLISH_GROUP_ID=io.github.chayanforyou
26+
PUBLISH_ARTIFACT_ID=slider
27+
PUBLISH_VERSION=1.0.0

library/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ android {
2828
dependencies {
2929
implementation 'androidx.appcompat:appcompat:1.5.1'
3030
implementation 'com.squareup.picasso:picasso:2.71828'
31-
}
31+
}
32+
apply from: './publish-mavencentral.gradle'
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
apply plugin: 'maven-publish'
2+
apply plugin: 'signing'
3+
4+
5+
group = PUBLISH_GROUP_ID
6+
version = PUBLISH_VERSION
7+
8+
ext["ossrhUsername"] = ''
9+
ext["ossrhPassword"] = ''
10+
ext["signingKey"] = ''
11+
ext["signingPassword"] = ''
12+
13+
File secretPropsFile = project.rootProject.file('local.properties')
14+
if (secretPropsFile.exists()) {
15+
Properties p = new Properties()
16+
p.load(new FileInputStream(secretPropsFile))
17+
p.each { name, value -> ext[name] = value }
18+
}
19+
20+
task androidSourcesJar(type: Jar) {
21+
archiveClassifier.set('sources')
22+
if (project.plugins.findPlugin("com.android.library")) {
23+
from android.sourceSets.main.java.srcDirs
24+
from android.sourceSets.main.kotlin.srcDirs
25+
} else {
26+
from sourceSets.main.java.srcDirs
27+
from sourceSets.main.kotlin.srcDirs
28+
}
29+
}
30+
31+
afterEvaluate {
32+
publishing {
33+
publications {
34+
release(MavenPublication) {
35+
groupId PUBLISH_GROUP_ID
36+
artifactId PUBLISH_ARTIFACT_ID
37+
version PUBLISH_VERSION
38+
39+
from components.release
40+
artifact androidSourcesJar
41+
42+
pom {
43+
name = 'AndroidImageSlider Library'
44+
description = 'An amazing and convenient Android image slider.'
45+
url = 'https://github.com/chayanforyou/AndroidImageSlider'
46+
47+
licenses {
48+
license {
49+
name = 'MIT License'
50+
url = 'http://opensource.org/licenses/MIT'
51+
}
52+
}
53+
developers {
54+
developer {
55+
id = 'chayanforyou'
56+
name = 'Chayan Mistry'
57+
email = 'chayanforyou@yahoo.com'
58+
}
59+
}
60+
scm {
61+
connection = 'scm:git:git://github.com/chayanforyou/AndroidImageSlider.git'
62+
developerConnection = 'scm:git:ssh://github.com:chayanforyou/AndroidImageSlider.git'
63+
url = 'https://github.com/chayanforyou/AndroidImageSlider.git'
64+
}
65+
}
66+
}
67+
}
68+
repositories {
69+
maven {
70+
name = "sonatype"
71+
72+
def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
73+
def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
74+
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
75+
76+
credentials {
77+
username ossrhUsername
78+
password ossrhPassword
79+
}
80+
}
81+
}
82+
}
83+
84+
signing {
85+
useInMemoryPgpKeys(signingKey, signingPassword)
86+
sign publishing.publications
87+
}
88+
}

0 commit comments

Comments
 (0)