forked from isaac-udy/Enro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
common_publish.gradle
191 lines (167 loc) · 7.38 KB
/
common_publish.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
def versionProperties = new Properties()
versionProperties.load(new FileInputStream(rootProject.file("version.properties")))
ext.versionCode = versionProperties.getProperty("versionCode").toInteger()
ext.versionName = versionProperties.getProperty("versionName")
def privateProperties = new Properties()
def privatePropertiesFile = rootProject.file("private.properties")
if (privatePropertiesFile.exists()) {
privateProperties.load(new FileInputStream(rootProject.file("private.properties")))
} else {
privateProperties.setProperty("githubUser", System.getenv("PUBLISH_GITHUB_USER") ?: "MISSING")
privateProperties.setProperty("githubToken", System.getenv("PUBLISH_GITHUB_TOKEN") ?: "MISSING")
privateProperties.setProperty("sonatypeUser", System.getenv("PUBLISH_SONATYPE_USER") ?: "MISSING")
privateProperties.setProperty("sonatypePassword", System.getenv("PUBLISH_SONATYPE_PASSWORD") ?: "MISSING")
privateProperties.setProperty("signingKeyId", System.getenv("PUBLISH_SIGNING_KEY_ID") ?: "MISSING")
privateProperties.setProperty("signingKeyPassword", System.getenv("PUBLISH_SIGNING_KEY_PASSWORD") ?: "MISSING")
privateProperties.setProperty("signingKeyLocation", System.getenv("PUBLISH_SIGNING_KEY_LOCATION") ?: "MISSING")
}
ext.publishAndroidModule = { String groupName, String moduleName, String versionSuffix = "" ->
publishModule(true, groupName, moduleName, versionSuffix)
}
ext.publishJavaModule = { String groupName, String moduleName, String versionSuffix = "" ->
publishModule(false, groupName, moduleName, versionSuffix)
}
ext.publishModule = { Boolean isAndroid, String groupName, String moduleName, String versionSuffix = "" ->
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext["signing.keyId"] = privateProperties['signingKeyId']
ext["signing.password"] = privateProperties['signingKeyPassword']
ext["signing.secretKeyRingFile"] = privateProperties['signingKeyLocation']
if(isAndroid) {
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.srcDirs
}
artifacts {
archives androidSourcesJar
}
}
else {
javadoc {
source = sourceSets.main.allJava
classpath = configurations.compileClasspath
options {
setMemberLevel JavadocMemberLevel.PUBLIC
setAuthor true
links "https://docs.oracle.com/javase/8/docs/api/"
}
}
task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.java.srcDirs
}
task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
from javadoc
}
artifacts {
archives sourcesJar
archives javadocJar
}
}
afterEvaluate {
group = groupName
version = versionName + versionSuffix
publishing {
publications {
release(MavenPublication) {
if(isAndroid) {
from components.release
}
else {
from components.java
}
groupId groupName
artifactId moduleName
version versionName + versionSuffix
if(isAndroid) {
artifact androidSourcesJar
}
else {
artifact sourcesJar
artifact javadocJar
}
pom {
name = moduleName
description = "A component of Enro, a small navigation library for Android"
url = "https://github.com/isaac-udy/Enro"
licenses {
license {
name = 'Enro License'
url = 'https://github.com/isaac-udy/Enro/blob/main/LICENSE'
}
}
developers {
developer {
id = 'isaac.udy'
name = 'Isaac Udy'
email = 'isaac.udy@gmail.com'
}
}
scm {
connection = 'scm:git:github.com/isaac-udy/Enro.git'
developerConnection = 'scm:git:ssh://github.com/isaac-udy/Enro.git'
url = 'https://github.com/isaac-udy/Enro/tree/main'
}
if(isAndroid) {
withXml {
def dependenciesNode = asNode().getAt('dependencies')[0] ?: asNode().appendNode('dependencies')
// Iterate over the implementation dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
}
repositories {
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/isaac-udy/Enro")
credentials {
username = privateProperties['githubUser']
password = privateProperties['githubToken']
}
}
}
repositories {
maven {
// This is an arbitrary name, you may also use "mavencentral" or
// any other name that's descriptive for you
name = "sonatype"
url = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/"
credentials {
username privateProperties['sonatypeUser']
password privateProperties['sonatypePassword']
}
}
}
}
if (privateProperties['signingKeyId'] != "MISSING") {
signing {
sign publishing.publications
}
}
}
afterEvaluate {
if(isAndroid) {
tasks.findByName("publishToMavenLocal")
.dependsOn("assembleRelease")
}
else {
tasks.findByName("publishToMavenLocal")
.dependsOn("assemble")
}
tasks.findByName("publish")
.dependsOn("publishToMavenLocal")
tasks.findByName("publishAllPublicationsToSonatypeRepository")
.dependsOn("publishToMavenLocal")
}
}