forked from googleapis/gax-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
546 lines (466 loc) · 15.5 KB
/
build.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
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
import groovy.io.FileType
buildscript {
repositories {
mavenLocal()
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
jcenter()
}
dependencies {
classpath "net.ltgt.gradle:gradle-apt-plugin:0.10",
"com.github.jengelman.gradle.plugins:shadow:1.2.4",
"io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.8.0",
"gradle.plugin.com.dorongold.plugins:task-tree:1.5"
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8"
}
}
apply plugin: 'java'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'io.codearte.nexus-staging'
// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "1.65.2-SNAPSHOT" // {x-version-update:gax:current}
ext {
// Project names not used for release
nonReleaseProjects = ['benchmark']
// Project names not using the default publication configuration
noDefaultPublications = ['benchmark', 'gax-bom']
libraryVendor = 'Google'
}
googleJavaFormat {
exclude '.apt_generated/**'
exclude 'bin/**'
exclude 'build/**'
exclude 'bazel*/**'
}
// google-java-format-gradle-plugin:0.8 does not work with Java 1.7.
verifyGoogleJavaFormat.onlyIf { JavaVersion.current().isJava8Compatible() }
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword') &&
!nonReleaseProjects.contains(project.name)) {
// Nexus staging plugin only works at root project level
// See https://github.com/Codearte/gradle-nexus-staging-plugin/issues/47
nexusStaging {
username = ossrhUsername
password = ossrhPassword
packageGroup = "com.google.api"
}
}
allprojects {
repositories {
mavenCentral() // for google-java-format's dependency
}
// Formatting tasks
// ================
apply plugin: 'com.github.sherter.google-java-format'
test.dependsOn verifyGoogleJavaFormat
verifyGoogleJavaFormat.onlyIf { JavaVersion.current().isJava8Compatible() }
task verifyLicense {
doLast {
def licenseText = new File(rootProject.rootDir, 'license-header-javadoc.txt').text
def srcFiles = []
sourceSets
.collectMany{it.allJava.getSrcDirs()}
.grep{it.exists()}
.each{it.eachFileRecurse(FileType.FILES, {srcFiles << new Tuple(it, it.text)})}
srcFiles = srcFiles
.findAll{it.get(0).path.endsWith(".java")}
.collect{new Tuple(it.get(0), it.get(1).replaceAll("Copyright 20[0-9]{2}", "Copyright 20xx"))}
.findAll{!it.get(1).startsWith(licenseText)}
if (srcFiles.asList().size() > 0) {
srcFiles.each({println 'missing license: ' + it.get(0)})
throw new IllegalStateException("Above files do not have licenses")
}
}
}
test.dependsOn verifyLicense
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
}
subprojects {
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: "net.ltgt.apt"
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'maven-publish'
apply plugin: 'com.dorongold.task-tree'
group = "com.google.api"
sourceCompatibility = 1.7
targetCompatibility = 1.7
// Dependencies
// ------------
jacoco {
toolVersion = "0.8.5"
}
ext {
// Load Dependencies shared between Bazel and Gradle build scripts
libraries = new Properties()
file(new File(rootDir, "dependencies.properties")).withReader{ libraries.load((Reader) it) }
// Gradle-specific build script dependencies
libraries.putAll([
'maven.io_grpc_grpc_bom': "io.grpc:grpc-bom:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_core': "io.grpc:grpc-core:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_context': "io.grpc:grpc-context:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_stub': "io.grpc:grpc-stub:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_auth': "io.grpc:grpc-auth:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_protobuf': "io.grpc:grpc-protobuf:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_netty_shaded': "io.grpc:grpc-netty-shaded:${libraries['version.io_grpc']}",
'maven.io_grpc_grpc_alts': "io.grpc:grpc-alts:${libraries['version.io_grpc']}",
'maven.com_google_protobuf': "com.google.protobuf:protobuf-java:${libraries['version.com_google_protobuf']}",
'maven.com_google_protobuf_java_util': "com.google.protobuf:protobuf-java-util:${libraries['version.com_google_protobuf']}"
])
}
repositories {
mavenLocal()
mavenCentral()
}
configurations {
shadowNoGuava
linkageChecker
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it,
exclude: ['**/AutoValue_*'])
})
}
}
check.dependsOn jacocoTestReport
// Source jar
// ----------
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource, sourceSets.test.allSource, sourceSets.main.resources.srcDirs
exclude('**/*Test.java')
}
// JavaDocV1 html
// -------
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/7/docs/api/'
if (JavaVersion.current().isJava8Compatible()) {
addStringOption('Xdoclint:all,-missing', '-quiet')
}
if (JavaVersion.current().isJava11Compatible()) {
addStringOption('-release', '7')
}
}
// JavaDocV3 - docFX
// -------
task javadocJarV3(type: Jar) {
classifier = 'javadoc'
from javadoc
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/7/docs/api/'
if (JavaVersion.current().isJava8Compatible()) {
addStringOption('Xdoclint:all,-missing', '-quiet')
}
if (JavaVersion.current().isJava11Compatible()) {
addStringOption('-release', '7')
}
}
// Test jar
// --------
task testlibJar(type: Jar, dependsOn: test) {
classifier = 'testlib'
from sourceSets.test.output
include('com/google/api/gax/rpc/testing/**')
include('com/google/api/gax/grpc/testing/**')
include('com/google/api/gax/httpjson/testing/**')
}
// ShadowJar
// ---------
shadowJar {
classifier = 'guavashaded'
relocate 'com.google.common', 'com.google.api.gax.repackaged.com.google.common'
relocate 'io.grpc.stub', 'com.google.api.gax.repackaged.io.grpc.stub'
relocate 'io.grpc.protobuf', 'com.google.api.gax.repackaged.io.grpc.protobuf'
configurations = [project.configurations.shadowNoGuava]
exclude('io/grpc/*')
exclude('io/grpc/internal/**')
exclude('io/grpc/inprocess/**')
exclude('io/grpc/util/**')
}
// Test Logging
// ------------
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat = 'full'
}
}
// Eclipse Annotation Processing
// -----------------------------
ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}
configurations {
codeGeneration
compile.exclude group: 'com.google.guava', module: 'guava-jdk5'
}
dependencies {
codeGeneration libraries['maven.com_google_auto_value_auto_value'],
libraries['maven.com_google_code_findbugs_jsr305']
// Separate configuration (class path) for Linkage Checker
linkageChecker "com.google.cloud.tools:dependencies:1.4.0"
}
compileJava.classpath += configurations.codeGeneration
eclipse {
jdt.file.withProperties {
it['org.eclipse.jdt.core.compiler.processAnnotations'] = 'enabled'
}
}
tasks.eclipseJdt {
doFirst {
def aptPrefs =
file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs")
aptPrefs.parentFile.mkdirs()
aptPrefs.text = """\
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=${eclipseAptFolder}
org.eclipse.jdt.apt.reconcileEnabled=true
""".stripIndent()
file('.factorypath').withWriter {
new groovy.xml.MarkupBuilder(it).'factorypath' {
project.configurations.codeGeneration.each { dep->
factorypathentry(
kind:'EXTJAR',
id:dep.absolutePath,
enabled:true,
runInBatchMode:false)
}
}
}
}
}
tasks.cleanEclipseJdt {
doFirst {
delete file("${eclipseSettingsDir}/org.eclipse.jdt.apt.core.prefs"),
file('.factorypath')
}
}
// Publishing
// ----------
afterEvaluate {
if (!noDefaultPublications.contains(project.name)) {
publishing {
publications {
mavenJava(MavenPublication) {
version = project.version
from components.java
artifact javadocJar
artifact sourcesJar
artifact shadowJar
artifact testlibJar
pom {
name = 'GAX (Google Api eXtensions) for Java'
packaging = 'jar'
artifactId = project.name
description = 'Google Api eXtensions for Java'
url = 'https://github.com/googleapis/gax-java'
scm {
url = 'https://github.com/googleapis/gax-java'
connection = 'scm:git:https://github.com/googleapis/gax-java.git'
}
licenses {
license {
name = 'BSD'
url = 'https://github.com/googleapis/gax-java/blob/master/LICENSE'
}
}
developers {
developer {
id = 'GoogleAPIs'
name = 'GoogleAPIs'
email = '[email protected]'
url = 'https://github.com/googleapis/gax-java'
organization = 'Google LLC'
organizationUrl = 'https://www.google.com'
}
}
}
}
}
repositories {
maven {
url 'https://google.oss.sonatype.org/service/local/staging/deploy/maven2/'
credentials {
username = project.hasProperty('ossrhUsername') ? project.getProperty('ossrhUsername') : null
password = project.hasProperty('ossrhPassword') ? project.getProperty('ossrhPassword') : null
}
}
}
}
task checkJavaLinkage(type: JavaExec) {
// Example invocation:
// ./gradlew gax-httpjson:checkJavaLinkage
dependsOn project.getTasksByName('publishMavenJavaPublicationToMavenLocal', true)
classpath = configurations.linkageChecker
main = 'com.google.cloud.tools.opensource.classpath.LinkageCheckerMain'
def arguments = ['-a', "com.google.api:${project.name}:${project.version}"]
if (project.name == 'gax-grpc') {
// The exclusion file can be regenerated by '-o' option. See its Wiki for details:
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/LinkageCheckerMain#exclusion-files
arguments += ['--exclusion-file', 'linkage-checker-exclusion.xml']
}
args arguments
}
}
signing {
if (!project.hasProperty('skip.signing') && !noDefaultPublications.contains(project.name)) {
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign publishing.publications.mavenJava
}
}
}
}
// JavaDocV1 html
// -------
task javadocCombined(type: Javadoc) {
source subprojects.collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = new File(projectDir, 'tmp_docs')
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/7/docs/api/'
}
clean {
delete 'tmp_gh-pages/'
delete 'tmp_docs/'
}
// JavaDocV3 docFX
// -------
task javadocCombinedV3(type: Javadoc) {
source subprojects.collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = new File(projectDir, 'tmp_docs/docfx-yml')
options.addStringOption('encoding', 'UTF-8')
options.addStringOption("doclet", "com.microsoft.doclet.DocFxDoclet")
options.addStringOption("projectname", "gax")
options.docletpath = [file(System.getenv('KOKORO_GFILE_DIR') + "/java-docfx-doclet-1.0.jar")]
}
clean {
delete 'tmp_gh-pages/'
delete 'tmp_docs/'
}
// Release
// =======
task checkOutGhPages {
doLast {
exec {
commandLine 'git', 'clone', '--branch', 'gh-pages',
'--single-branch', '[email protected]:googleapis/gax-java.git', 'tmp_gh-pages'
}
}
}
task copyFilesToGhPages {
dependsOn 'checkOutGhPages'
dependsOn 'javadocCombined'
doLast {
def newSiteDirPath = 'tmp_gh-pages/' + project.version + '/apidocs/'
new File(newSiteDirPath).mkdirs()
copy {
from 'tmp_docs'
into newSiteDirPath
}
copy {
from 'README.md'
into 'tmp_gh-pages'
rename { filename -> filename.replace 'README', 'index' }
}
delete('tmp_gh-pages/latest/')
def latestDirPath = 'tmp_gh-pages/latest/apidocs/'
new File(latestDirPath).mkdirs()
copy {
from 'tmp_docs'
into latestDirPath
}
}
}
task createApiDocsRedirect {
dependsOn 'copyFilesToGhPages'
doLast {
def template = new File('templates/apidocs_index.html.template').text
def outputContent = template.replace('{{siteVersion}}', project.version)
new File('tmp_gh-pages/apidocs/index.html').write(outputContent)
}
}
task publishDocs {
dependsOn 'closeAndReleaseRepository'
doLast {
exec {
workingDir './tmp_gh-pages'
commandLine 'git', 'add', '.'
}
exec {
workingDir './tmp_gh-pages'
commandLine 'git', 'commit', '-m', 'Release docs for ' + project.version
}
exec {
workingDir './tmp_gh-pages'
commandLine 'git', 'push'
}
}
}
// 1. Updates samples/pom.xml
// 2. Updates README.md
// 3. Regenerates the gh-pages branch under tmp_gh-pages
// 4. Stages the artifact on Sonatype
task stageRelease {
dependsOn 'createApiDocsRedirect'
doLast {
exec {
// We need to spawn a new gradle build process in order to upload appropriately
// More details: http://stackoverflow.com/questions/31614735/gradle-uploadarchives-artificats-namespace-when-depending-on-a-plugin
commandLine './gradlew', 'publish'
}
}
}
// 1. Closes and releases the artifact on Sonatype
// 2. Commits and pushes the new docs
// 3. Remove tmp_gh-pages
// Note: This task assumes that the 'stage_release' task has been completed.
task finalizeRelease {
dependsOn 'publishDocs'
doLast {
exec {
commandLine 'rm', '-r', 'tmp_gh-pages'
}
}
}
// Linkage Monitor searches for pom.xml but gax-java uses Gradle. Alternatively Linkage Monitor
// reads linkage-monitor-artifacts.txt to get list of artifacts.
// https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/Linkage-Monitor#linkage-monitor-artifactstxt
task createLinkageMonitorArtifactList {
doLast {
def httpJsonVersion = project(":gax-httpjson").version
new File(projectDir, "linkage-monitor-artifacts.txt").text = """
com.google.api:gax:$version
com.google.api:gax-grpc:$version
com.google.api:gax-httpjson:$httpJsonVersion
"""
}
}