This repository has been archived by the owner on Sep 26, 2023. It is now read-only.
/
build.gradle
448 lines (388 loc) · 13.3 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
import groovy.io.FileType
plugins {
id 'java'
id 'io.github.gradle-nexus.publish-plugin' version '1.1.0'
id 'com.diffplug.eclipse.apt' version '3.33.2' apply false
id 'com.dorongold.task-tree' version '2.1.0' apply false
id 'com.github.johnrengelman.shadow' version '7.1.0' apply false
id 'com.github.sherter.google-java-format' version '0.9' apply false
}
// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "2.7.0" // {x-version-update:gax:current}
allprojects {
group = 'com.google.api'
}
// Project names not used for release
def nonReleaseProjects = ['benchmark']
// Project names not using the default publication configuration
def noDefaultPublications = ['benchmark', 'gax-bom']
def nonJavaProjects = ['gax-bom']
ext {
libraryVendor = 'Google'
// Load Dependencies shared between Bazel and Gradle build scripts
libraries = new Properties()
file('dependencies.properties').withReader { libraries.load(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_api': "io.grpc:grpc-api:${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.io_grpc_grpc_xds': "io.grpc:grpc-xds:${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']}")
}
nexusPublishing {
packageGroup = 'com.google.api'
repositories {
sonatype {
nexusUrl = uri('https://google.oss.sonatype.org/service/local/')
snapshotRepositoryUrl = uri('https://google.oss.sonatype.org/content/repositories/snapshots/')
username = findProperty('ossrhUsername')
password = findProperty('ossrhPassword')
}
}
}
def javaProjects = subprojects.findAll { !nonJavaProjects.contains(it.name) }
configure(javaProjects) {
apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'com.diffplug.eclipse.apt'
apply plugin: 'com.dorongold.task-tree'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.github.sherter.google-java-format'
sourceCompatibility = 1.8
targetCompatibility = 1.8
// Formatting tasks
// ================
googleJavaFormat {
toolVersion '1.7'
exclude '.apt_generated*/**'
exclude 'bin/**'
exclude 'build/**'
exclude 'bazel*/**'
}
test.dependsOn verifyGoogleJavaFormat
task verifyLicense {
doLast {
def licenseText = new File('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
tasks.withType(JavaCompile) {
options.compilerArgs << '-Xlint:unchecked' << '-Xlint:deprecation'
}
// Dependencies
// ------------
repositories {
mavenLocal()
mavenCentral()
}
configurations {
shadowNoGuava
linkageChecker
implementation.exclude group: 'com.google.guava', module: 'guava-jdk5'
}
dependencies {
// Separate configuration (class path) for Linkage Checker
linkageChecker 'com.google.cloud.tools:dependencies:1.5.12'
}
jacoco.toolVersion = '0.8.5'
jacocoTestReport {
reports {
xml.required = true
html.required = true
}
afterEvaluate {
getClassDirectories().setFrom files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['**/AutoValue_*'])
})
}
}
check.dependsOn jacocoTestReport
// Source jar
// ----------
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = 'sources'
from sourceSets.main.allSource, sourceSets.test.allSource, sourceSets.main.resources.srcDirs
exclude('**/*Test.java')
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/8/docs/api/'
if (JavaVersion.current().isJava8Compatible()) {
addStringOption('Xdoclint:all,-missing', '-quiet')
}
if (JavaVersion.current().isJava11Compatible()) {
addStringOption('-release', '8')
}
}
// JavaDocV1 html
// -------
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
// JavaDocV3 - docFX
// -------
task javadocJarV3(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
// Test jar
// --------
task testlibJar(type: Jar, dependsOn: test) {
archiveClassifier = '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 {
archiveClassifier = '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 auto-setup
eclipse.synchronizationTasks eclipseJdtApt, eclipseJdt, eclipseFactorypath
}
def normalReleasableProjects = subprojects.findAll {
!nonReleaseProjects.contains(it.name) && !noDefaultPublications.contains(it.name)
}
configure(normalReleasableProjects) {
apply plugin: 'maven-publish'
apply plugin: 'signing'
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
version = project.version
from components.java
artifact javadocJar
artifact sourcesJar
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 = 'googleapis@googlegroups.com'
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 = findProperty('ossrhUsername')
password = findProperty('ossrhPassword')
}
}
}
}
task checkJavaLinkage(type: JavaExec) {
// Example invocation:
// ./gradlew gax-httpjson:checkJavaLinkage
dependsOn project.getTasksByName('publishMavenJavaPublicationToMavenLocal', true)
classpath = configurations.linkageChecker
mainClass = '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 {
required { gradle.taskGraph.hasTask ":${name}:publishToSonatype" }
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign publishing.publications
}
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/7/docs/api/'
}
// JavaDocV1 html
// -------
task javadocCombined(type: Javadoc) {
source subprojects.collect {project -> project.sourceSets.main.allJava }
classpath = files(subprojects.collect {project -> project.sourceSets.main.compileClasspath})
destinationDir = file('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 = file('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.3.0.jar')]
// Newer Gradle 6 passes -notimestamp by default, which the doclet above doesn't understand:
// https://github.com/gradle/gradle/issues/11898
options.noTimestamp false
}
clean {
delete 'tmp_gh-pages/'
delete 'tmp_docs/'
}
// Release
// =======
task checkOutGhPages {
doLast {
exec {
commandLine 'git', 'clone', '--branch', 'gh-pages',
'--single-branch', 'git@github.com: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 'closeAndReleaseSonatypeStagingRepository'
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('linkage-monitor-artifacts.txt').text = """
com.google.api:gax:$version
com.google.api:gax-grpc:$version
com.google.api:gax-httpjson:$httpJsonVersion
"""
}
}