forked from googleapis/gax-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
329 lines (279 loc) · 9.79 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
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.40.0' apply false
id 'com.dorongold.task-tree' version '2.1.1' apply false
id 'com.github.johnrengelman.shadow' version '7.1.2' apply false
id 'com.github.sherter.google-java-format' version '0.9' apply false
id 'org.sonarqube' version '3.5.0.2730'
}
// TODO: Populate this from dependencies.properties version property (for proper Gradle-Bazel sync)
project.version = "2.20.1" // {x-version-update:gax:current}
allprojects {
group = 'com.google.api'
}
// Project names not using the default publication configuration
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_googleapis': "io.grpc:grpc-googleapis:${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'
// This flag is only available in JDK 9+. This flag ensures the generated
// bytecode is compatible with Java 8. (targetCompatibility = 1.8 is not
// sufficient)
options.compilerArgs.addAll(['--release', '8'])
}
// Dependencies
// ------------
repositories {
mavenLocal()
mavenCentral()
}
configurations {
shadowNoGuava
implementation.exclude group: 'com.google.guava', module: 'guava-jdk5'
}
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
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 {
!nonJavaProjects.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 = '[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 = findProperty('ossrhUsername')
password = findProperty('ossrhPassword')
}
}
}
}
}
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.5.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_docs/'
}
sonarqube {
properties {
property 'sonar.projectKey', 'googleapis_gax-java'
property 'sonar.organization', 'googleapis'
property 'sonar.host.url', 'https://sonarcloud.io'
}
}