-
Notifications
You must be signed in to change notification settings - Fork 2
/
publish.gradle
486 lines (391 loc) · 20.1 KB
/
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
/*
* Copyright (C) 2015-2017 akha, a.k.a. Alexander Kharitonov
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
File localPropertiesFile = project.rootProject.file('local.properties')
Properties localProperties = localPropertiesFile.exists() ? new Properties(): null
if (localProperties != null) {
localProperties.load(localPropertiesFile.newDataInputStream())
}
def getProperty = { String cfgKey, String envKey, String defValue ->
String locProperty = cfgKey == null || localProperties == null ? null: localProperties.getProperty(cfgKey)
String envProperty = envKey == null ? null: System.getenv(envKey)
String cfgProperty = cfgKey != null && project.hasProperty(cfgKey) ? project.property(cfgKey): null
return locProperty != null ? locProperty: cfgProperty != null ? cfgProperty: envProperty != null ? envProperty:
defValue != null ? defValue: System.console().readLine(
System.getProperty('line.separator') + (envKey != null ? envKey: cfgKey) + ': ')
}
def getPropertyExt = { String key ->
return project.ext.has(key) ? project.ext.get(key): rootProject.ext.has(key) ? rootProject.ext.get(key): getProperty(key, null, '')
}
def getPropertyExtArray = { String key ->
return project.ext.has(key) ? project.ext.get(key): rootProject.ext.get(key)
}
boolean projectPublish = getProperty('publish', null, 'false') == 'true'
if (getProperty('javadoc', null, 'true') == 'false') {
if (projectPublish) {
println(' Publish without javadoc is not allowed')
}
return
}
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'
version = getPropertyExt('publishedVersion')
group = getPropertyExt('publishedGroupId')
def pomConfig = {
def nodeRoot = asNode()
String dependencies = 'dependencies', packaging = 'packaging'
//noinspection ChangeToOperator
boolean addDependencies = nodeRoot.getAt(dependencies).size() == 0
//noinspection ChangeToOperator
boolean addPackaging = nodeRoot.getAt(packaging) .size() == 0
if (addPackaging) {
nodeRoot.appendNode(packaging, getPropertyExt('publishedPackaging'))
}
nodeRoot.children().last() + {
//noinspection UnnecessaryQualifiedReference
resolveStrategy Closure.DELEGATE_FIRST
name getPropertyExt('publishedName')
description getPropertyExt('publishedDescription')
url getPropertyExt('urlSite')
inceptionYear getPropertyExt('projectYear')
scm {
connection getPropertyExt('urlGit')
developerConnection getPropertyExt('urlGit')
url getPropertyExt('urlSite')
}
issueManagement {
system getPropertyExt('projectIssueManagement')
url getPropertyExt('urlIssues')
}
licenses {
license {
//noinspection GroovyAssignabilityCheck
name getPropertyExt('licenseName')
url getPropertyExt('licenseUrl')
//noinspection GroovyAssignabilityCheck
distribution getPropertyExt('licenseDistribution')
}
}
developers {
developer {
id getPropertyExt('developerId')
//noinspection GroovyAssignabilityCheck
name getPropertyExt('developerName')
email getPropertyExt('developerEmail')
url getPropertyExt('urlSite')
}
}
}
//noinspection ChangeToOperator
def nodeRoles = nodeRoot.getAt('developers').get(0).getAt('developer').get(0).appendNode('roles')
getPropertyExtArray('developerRoles').each {
nodeRoles.appendNode('role', it)
}
if (addDependencies) {
def nodeDependencies = nodeRoot.appendNode(dependencies)
configurations.compile.allDependencies.each {
def nodeDependency = nodeDependencies.appendNode('dependency')
nodeDependency.appendNode('groupId', it.group)
nodeDependency.appendNode('artifactId', it.name)
nodeDependency.appendNode('version', it.version)
nodeDependency.appendNode('scope', 'compile')
}
}
}
String classifierJavadoc = 'javadoc', classifierSources = 'sources'
//noinspection GroovyAssignabilityCheck
List<String> flavorList = new ArrayList<String>(), linkList = new ArrayList<String>(getPropertyExtArray('projectJavaDocLinks'))
List<JavadocOfflineLink> linkOfflineList = new ArrayList<JavadocOfflineLink>()
def getLocProperty = { String key, String addKey ->
if (localProperties == null) {
return null
}
else {
String locProperty = addKey == null ? null: localProperties.getProperty(key + '.' + addKey)
return locProperty != null ? locProperty: localProperties.getProperty(key)
}
}
def javadocWindowTitle = { String title ->
return title.capitalize() + ' ' + getPropertyExt('publishedVersion') + ' API'
}
def javadocTitle = { String title ->
return '<table border="0"><tr><td><img src="logo.png" alt=""></td><td> ' +
javadocWindowTitle(title) + '</td</tr></table>'
}
def javadocConfig = { options, addKey ->
options.locale 'en_US'
options.charSet 'UTF-8'
options.encoding 'UTF-8'
options.bottom getPropertyExt('projectCopyright')
options.setLinks linkList + 'http://docs.oracle.com/javase/8/docs/api/'
options.docTitle javadocTitle (getPropertyExt('publishedArtifactId'))
options.windowTitle javadocWindowTitle(getPropertyExt('publishedArtifactId'))
options.noTimestamp true
options.tags 'yakhont.preprocessor.remove.in.generated:X'
//noinspection GroovyAssignabilityCheck
String docletProperty = getLocProperty('doclet', addKey)
if (docletProperty == null) {
options.tags 'exclude:X', 'yakhont.see:X', 'yakhont.link:X'
}
else {
options.doclet docletProperty
List<File> fileList = new ArrayList<File>()
//noinspection GroovyAssignabilityCheck
getLocProperty('doclet.path', addKey).split(File.pathSeparator).each {
fileList.add(new File(it))
}
options.setDocletpath fileList
}
//noinspection GroovyAssignabilityCheck
String docletOptions = getLocProperty('doclet.options', addKey)
if (docletOptions == null) {
return
}
docletOptions.split('::').each {
String[] docletOption = it.split('->')
switch (docletOption.length) {
case 1:
options.addOption new JavadocOptionFileOption<String>() {
public String getOption() {
return docletOption[0]
}
public String getValue() {
return null
}
public void setValue(String value) {
}
@SuppressWarnings("UnnecessaryQualifiedReference")
public void write(org.gradle.external.javadoc.internal.JavadocOptionFileWriterContext context) throws IOException {
context.writeOption(docletOption[0])
}
}
break
case 2:
if (docletOption[0] == 'tags' ) {
options.tags Arrays.asList(docletOption[1].split(','))
}
else if (docletOption[0] == 'taglets') {
options.taglets Arrays.asList(docletOption[1].split(','))
}
else {
options.addStringOption docletOption[0], docletOption[1]
}
break
default:
println 'wrong doclet option ' + docletOption[0]
break
}
}
}
// disable the doclint tool in Java 8
if (JavaVersion.current().isJava8Compatible()) {
allprojects {
tasks.withType(Javadoc) {
options.addStringOption('Xdoclint:none', '-quiet')
}
}
}
boolean isAndroidApp = project.plugins.hasPlugin('com.android.application')
boolean isAndroidLib = project.plugins.hasPlugin('com.android.library')
if (isAndroidApp || isAndroidLib) {
boolean makeReleaseBuilds = !android.defaultPublishConfig.endsWith('Debug')
android.variantFilter { variant ->
//noinspection ChangeToOperator
if ((variant.buildType.name.equals('debug') && makeReleaseBuilds) ||
(variant.buildType.name.equals('release') && !makeReleaseBuilds)) {
variant.setIgnore(true);
}
}
project.ext.archivesBaseName = getPropertyExt('publishedArtifactId')
//noinspection GroovyAssignabilityCheck
linkOfflineList.add(new JavadocOfflineLink('http://developer.android.com/reference/',
android.sdkDirectory.path + '/docs/reference/'))
//noinspection GroovyAssignabilityCheck
linkOfflineList.add(new JavadocOfflineLink('https://developers.google.com/android/reference/',
android.sdkDirectory.path + '/extras/google/google_play_services/docs/reference/'))
def makeArtifactsAndroid = { variant ->
variant.outputs.each { output ->
//noinspection GroovyAssignabilityCheck
output.outputFile = new File(output.outputFile.parent,
output.outputFile.name.replace('-release', '').replace('-' + getPropertyExt('projectDefaultFlavor'), ''))
//noinspection ChangeToOperator
boolean isDebugVariant = variant.buildType.name.equals('debug')
String flavorName = getPropertyExt('projectDefaultFlavor') == 'release' ? 'release':
variant.getVariantData().getVariantConfiguration().getFlavorName()
boolean isDefaultFlavor = flavorName == getPropertyExt('projectDefaultFlavor')
String appendixValue = isDefaultFlavor ? null: flavorName
String flavorAdded = '-' + flavorName
String flavorArtifactId = getPropertyExt('publishedArtifactId') + (isDefaultFlavor ? '': flavorAdded)
//noinspection GroovyAssignabilityCheck
Task javadoc = task('generate' + variant.name.capitalize() + 'Javadoc', type: Javadoc) {
source = android.sourceSets.main.java.srcDirs + android.sourceSets[flavorName].java.srcDirs
//noinspection GroovyAssignabilityCheck
classpath = variant.javaCompiler.classpath + project.files(android.getBootClasspath().join(File.pathSeparator))
//noinspection GroovyAssignabilityCheck
destinationDir = new File(project.docsDir, 'javadoc-' + variant.name)
options {
javadocConfig(options, flavorName)
}
options {
setLinksOffline linkOfflineList
docTitle javadocTitle (flavorArtifactId)
windowTitle javadocWindowTitle(flavorArtifactId)
}
failOnError = false
}
//noinspection GroovyAssignabilityCheck
Task javadocJar = task('generate' + variant.name.capitalize() + 'JavadocJar', type: Jar, dependsOn: javadoc) {
//noinspection GroovyAssignabilityCheck
from javadoc.destinationDir
baseName = getPropertyExt('publishedArtifactId')
appendix = appendixValue
classifier = classifierJavadoc
}
//noinspection GroovyAssignabilityCheck
Task sourcesJar = task('generate' + variant.name.capitalize() + 'SourcesJar', type: Jar) {
into('java-main' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.main .java.srcDirs }
into('java-' + flavorName ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName ].java.srcDirs }
if (isDebugVariant) {
into('java-debug' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.debug .java.srcDirs }
into('java-' + flavorName + 'Debug' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName + 'Debug' ].java.srcDirs }
}
else {
into('java-release' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.release .java.srcDirs }
into('java-' + flavorName + 'Release') { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName + 'Release'].java.srcDirs }
}
into('res-main' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.main .res .srcDirs }
into('res-' + flavorName ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName ].res .srcDirs }
if (isDebugVariant) {
into('res-debug' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.debug .res .srcDirs }
into('res-' + flavorName + 'Debug' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName + 'Debug' ].res .srcDirs }
}
else {
into('res-release' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets.release .res .srcDirs }
into('res-' + flavorName + 'Release' ) { //noinspection GroovyAssignabilityCheck
from android.sourceSets[flavorName + 'Release'].res .srcDirs }
}
if (variant.getBuildType().isMinifyEnabled()) { from variant.mappingFile }
baseName = getPropertyExt('publishedArtifactId')
appendix = appendixValue
classifier = classifierSources + (isDebugVariant ? '-debug': '')
duplicatesStrategy = DuplicatesStrategy.WARN
}
project.artifacts.archives output.outputFile, javadocJar, sourcesJar
install.repositories.mavenInstaller {
addFilter(flavorName) { artifact, file ->
isDefaultFlavor ? artifact.name == flavorArtifactId: artifact.name.contains(flavorAdded)
}
pom(flavorName).artifactId = flavorArtifactId
pom(flavorName).project {
packaging getPropertyExt('publishedPackaging')
groupId getPropertyExt('publishedGroupId')
//noinspection GroovyAssignabilityCheck
version getPropertyExt('publishedVersion')
}
pom(flavorName).withXml pomConfig
}
if (projectPublish && !isDebugVariant) {
publishing.publications.create(flavorName, MavenPublication) {
artifactId flavorArtifactId
pom.packaging getPropertyExt('publishedPackaging')
groupId getPropertyExt('publishedGroupId')
//noinspection GroovyAssignabilityCheck
version getPropertyExt('publishedVersion')
pom.withXml pomConfig
artifacts = [output.outputFile, javadocJar, sourcesJar]
}
flavorList.add(flavorName)
bintray.publications = flavorList.toArray()
println(' Added to bintray.publications: ' + flavorArtifactId)
}
}
}
if (isAndroidLib) {
android.libraryVariants.all { variant ->
makeArtifactsAndroid(variant)
}
}
if (isAndroidApp) {
android.applicationVariants.all { variant ->
makeArtifactsAndroid(variant)
}
}
}
if (project.plugins.hasPlugin('java')) {
//noinspection GroovyUnusedAssignment
archivesBaseName = getPropertyExt('publishedArtifactId')
install.repositories.mavenInstaller.pom.withXml pomConfig
javadoc {
options {
javadocConfig(options, null)
}
failOnError false
}
task sourceJar(type: Jar) {
from sourceSets.main.allSource
classifier = classifierSources
}
task javadocJar(type: Jar, dependsOn: javadoc) {
from javadoc.destinationDir
classifier = classifierJavadoc
}
artifacts.archives sourceJar, javadocJar
if (projectPublish) {
bintray.configurations = ['archives']
println(' Added to bintray.configurations: ' + archivesBaseName)
}
}
if ((bintray.publications == null || bintray.publications .length == 0) &&
(bintray.configurations == null || bintray.configurations.length == 0)) {
return
}
bintray {
user = getProperty('bintray.user', 'BINTRAY_USER', null)
key = getProperty('bintray.apikey', 'BINTRAY_API_KEY', '')
pkg {
repo = getPropertyExt('bintrayRepo')
name = getPropertyExt('bintrayName')
desc = getPropertyExt('publishedDescription')
websiteUrl = getPropertyExt('urlSite')
vcsUrl = getPropertyExt('urlGit')
issueTrackerUrl = getPropertyExt('urlIssues')
githubRepo = getPropertyExt('urlGitHubRepo')
githubReleaseNotesFile = getPropertyExt('projectReadme')
licenses = getPropertyExtArray('licenseList')
publish = true
publicDownloadNumbers = true
//noinspection GroovyAssignabilityCheck
version {
name = getPropertyExt('publishedVersion')
desc = getPropertyExt('publishedDescription')
gpg {
sign = true
passphrase = getProperty('bintray.gpg.password', null, null)
}
}
}
}