-
Notifications
You must be signed in to change notification settings - Fork 3
/
module_publish.gradle
238 lines (202 loc) · 8.73 KB
/
module_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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def rootProjectDir = rootDir.parent
class PublishModule {
Library library
Plugin plugin
void library(Action<Library> action) {
library = new Library()
action.execute(library)
}
void plugin(Action<Plugin> action) {
plugin = new Plugin()
action.execute(plugin)
}
}
class Library {
String groupId
String moduleName
String version
String description
String url
}
class Plugin {
String group
String id
String name
String displayName
String version
String implementationClass
String description
String url
Collection<String> tags
}
extensions.create("publishModule", PublishModule)
def mavenFileName = "maven.properties"
def localFileName = "local.properties"
println "Reading $mavenFileName and $localFileName..."
def mavenProp = new Properties()
def localProp = new Properties()
def mis
def lis
try {
def mavenFile = new File("${rootProjectDir}/${mavenFileName}")
if (mavenFile.exists()) {
mis = new FileInputStream(mavenFile)
mavenProp.load(mis)
println "Success to read $mavenFileName."
}
def localFile = new File("${rootProjectDir}/${localFileName}")
if (localFile.exists()) {
lis = new FileInputStream(localFile)
localProp.load(lis)
println "Success to read $localFileName."
}
def isCI = System.getenv().containsKey('CI')
if (mavenFile.exists() && (isCI || localFile.exists())) {
def snapshotRepoUrl = mavenProp.getProperty('repo.snapshotUrl')
def releaseRepoUrl = mavenProp.getProperty('repo.releaseUrl')
def licenseName = mavenProp.getProperty('license.name')
def licenseUrl = mavenProp.getProperty('license.url')
def developerName = mavenProp.getProperty('developer.name')
def developerEmail = mavenProp.getProperty('developer.email')
def gitRepoUrl = mavenProp.getProperty('git.repoUrl')
def signingId
def signingPassword
def signingPath
def sonatypeUsername
def sonatypePassword
if (isCI) {
println "Is in CI environment."
signingId = System.getenv('SIGNING_KEY_ID')
signingPassword = System.getenv('SIGNING_PASSWORD')
signingPath = System.getenv('SIGNING_PATH')
sonatypeUsername = System.getenv('SONATYPE_USERNAME')
sonatypePassword = System.getenv('SONATYPE_PASSWORD')
} else {
signingId = localProp.getProperty('signing.keyId')
signingPassword = localProp.getProperty('signing.password')
signingPath = localProp.getProperty('signing.path')
sonatypeUsername = localProp.getProperty('sonatype.username')
sonatypePassword = localProp.getProperty('sonatype.password')
}
afterEvaluate {
if (publishModule.library != null) {
println "Module $name has configuration that can publish to maven."
apply plugin: 'maven-publish'
apply plugin: 'signing'
ext."signing.keyId" = signingId
ext."signing.password" = signingPassword
ext."signing.secretKeyRingFile" = signingPath
task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from android.sourceSets.main.java.source
}
publishing {
repositories {
maven {
name = "AndroidLibraries"
url = version.endsWith('SNAPSHOT') ? snapshotRepoUrl : releaseRepoUrl
println "Maven repo url: $url"
credentials {
username sonatypeUsername
password sonatypePassword
}
}
}
publications {
release(MavenPublication) {
groupId = publishModule.library.groupId
artifactId = publishModule.library.moduleName
version = publishModule.library.version
def artifactOutputPath = "$buildDir/outputs/aar/${project.getName()}-release.aar"
artifact(artifactOutputPath)
artifact androidSourcesJar
println "groupId: $publishModule.library.groupId"
println "artifactId: $publishModule.library.moduleName"
println "version: $publishModule.library.version"
pom {
name = publishModule.library.moduleName
description = publishModule.library.description
url = publishModule.library.url
println "description: $publishModule.library.description"
println "url: $publishModule.library.url"
licenses {
license {
name = licenseName
url = licenseUrl
}
}
developers {
developer {
id = developerName
name = developerName
email = developerEmail
}
}
scm {
connection = "scm:git:${gitRepoUrl}.git"
developerConnection = "scm:git:ssh://${gitRepoUrl}.git"
url = "https://${gitRepoUrl}/tree/master"
}
def api = project.configurations.api.allDependencies
if (!api.isEmpty()) {
withXml {
def dependenciesNode = asNode().appendNode('dependencies')
api.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}
}
signing {
sign publishing.publications
}
}
if (publishModule.plugin != null) {
println "Module $name has configuration that can publish to gradle plugins."
apply plugin: 'java-gradle-plugin'
apply plugin: 'com.gradle.plugin-publish'
group = publishModule.plugin.group
version = publishModule.plugin.version
pluginBundle {
website = publishModule.plugin.url
vcsUrl = "${publishModule.plugin.url}.git"
tags = publishModule.plugin.tags
}
gradlePlugin {
plugins {
create(publishModule.plugin.name) {
id = publishModule.plugin.id
displayName = publishModule.plugin.displayName
description = publishModule.plugin.description
implementationClass = publishModule.plugin.implementationClass
}
}
}
println "group: ${publishModule.plugin.group}"
println "id: ${publishModule.plugin.id}"
println "name: ${publishModule.plugin.name}"
println "displayName: ${publishModule.plugin.displayName}"
println "version: ${publishModule.plugin.version}"
println "description: ${publishModule.plugin.description}"
println "url: ${publishModule.plugin.url}"
println "tags: ${publishModule.plugin.tags}"
}
}
}
} catch (Exception e) {
println "Failed to read properties."
println e
} finally {
if (mis != null) {
mis.close()
}
if (lis != null) {
lis.close()
}
}