This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
build.gradle
399 lines (340 loc) · 9.26 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
import groovy.io.FileType
buildscript {
repositories {
mavenLocal()
maven {
url 'https://plugins.gradle.org/m2/'
}
mavenCentral()
jcenter()
}
dependencies {
classpath "gradle.plugin.com.github.sherter.google-java-format:google-java-format-gradle-plugin:0.8",
"io.codearte.gradle.nexus:gradle-nexus-staging-plugin:0.21.2"
}
}
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'jacoco'
apply plugin: 'signing'
apply plugin: 'maven-publish'
apply plugin: 'com.github.sherter.google-java-format'
apply plugin: 'io.codearte.nexus-staging'
group = "com.google.api"
archivesBaseName = "api-common"
project.version = "1.10.1" // {x-version-update:api-common:current}
sourceCompatibility = 1.7
targetCompatibility = 1.7
// Dependencies
// ------------
ext {
// Shortcuts for libraries we are using
libraries = [
javax_annotations: 'javax.annotation:javax.annotation-api:1.3.2',
auto_value_annotations: 'com.google.auto.value:auto-value-annotations:1.7.4',
auto_value: 'com.google.auto.value:auto-value:1.7.4',
guava: 'com.google.guava:guava:29.0-android',
jsr305: 'com.google.code.findbugs:jsr305:3.0.2',
error_prone_annotations: 'com.google.errorprone:error_prone_annotations:2.4.0',
// Testing
junit: 'junit:junit:4.13.1',
truth: 'com.google.truth:truth:1.0.1',
]
}
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
annotationProcessor libraries.auto_value
compile libraries.guava,
libraries.jsr305,
libraries.javax_annotations,
libraries.auto_value_annotations
compileOnly libraries.error_prone_annotations
testCompile libraries.junit,
libraries.truth
}
clean.doFirst {
delete 'tmp_gh-pages/'
}
jacocoTestReport {
reports {
xml.enabled true
html.enabled true
}
}
check.dependsOn jacocoTestReport
// jar with automatic module name:
jar {
manifest {
attributes('Automatic-Module-Name': 'com.google.api.apicommon')
}
}
// Source jar
// ----------
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
// JavaDoc
// -------
task javadocJar(type: Jar) {
classifier = 'javadoc'
from javadoc
}
javadoc.options {
encoding = 'UTF-8'
links 'https://docs.oracle.com/javase/7/docs/api/'
}
// Test Logging
// ------------
test {
testLogging {
events "passed", "skipped", "failed", "standardOut", "standardError"
exceptionFormat = 'full'
}
}
// Eclipse Annotation Processing
// -----------------------------
ext {
eclipseAptFolder = '.apt_generated'
eclipseSettingsDir = file('.settings')
}
configurations {
codeGeneration
}
dependencies {
codeGeneration libraries.auto_value, libraries.jsr305
compile libraries.jsr305, libraries.auto_value_annotations
}
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
// ----------
artifacts {
archives javadocJar, sourcesJar
}
signing {
required { gradle.taskGraph.hasTask("uploadArchives") }
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign configurations.archives
}
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
nexusStaging {
username = ossrhUsername
password = ossrhPassword
packageGroup = "com.google.api"
}
}
afterEvaluate {
publishing {
publications {
mavenJava(MavenPublication) {
version = project.version
from components.java
artifact javadocJar
artifact sourcesJar
pom {
name = 'API Common'
packaging = 'jar'
artifactId = 'api-common'
description = 'Common utilities for Google APIs in Java'
url = 'https://github.com/googleapis/api-common-java'
scm {
url = 'https://github.com/googleapis/api-common-java'
connection = 'scm:git:https://github.com/googleapis/api-common-java.git'
}
licenses {
license {
name = 'BSD'
url = 'https://github.com/googleapis/api-common-java/blob/master/LICENSE'
}
}
developers {
developer {
id = 'GoogleAPIs'
name = 'GoogleAPIs'
email = 'googleapis@googlegroups.com'
url = 'https://github.com/googleapis'
organization = 'Google, Inc.'
organizationUrl = 'https://www.google.com'
}
}
}
}
}
repositories {
maven {
url 'https://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
}
}
}
}
signing {
if (!project.hasProperty('skip.signing')) {
if (project.hasProperty('signing.gnupg.executable')) {
useGpgCmd()
}
sign publishing.publications.mavenJava
}
}
}
gradle.projectsEvaluated {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
}
}
// Formatting tasks
// ================
task verifyLicense {
doLast {
def licenseText = new File(rootProject.rootDir, 'license-header-javadoc.txt').text
def srcFiles = []
sourceSets
.collectMany{it.allJava.getSrcDirs()}
.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
googleJavaFormat {
toolVersion '1.0'
}
tasks.googleJavaFormat {
exclude '.apt_generated/**'
exclude 'bin/**'
exclude 'build/**'
}
tasks.verifyGoogleJavaFormat {
exclude '.apt_generated/**'
exclude 'bin/**'
exclude 'build/**'
}
test.dependsOn verifyGoogleJavaFormat
// Release
// =======
task checkOutGhPages {
doLast {
if (!new File('tmp_gh-pages').exists()) {
exec {
commandLine 'git', 'clone', '--branch', 'gh-pages',
'--single-branch', 'https://github.com/googleapis/api-common-java/', 'tmp_gh-pages'
}
}
}
}
task copyFilesToGhPages {
dependsOn 'checkOutGhPages'
dependsOn 'javadoc'
doLast {
def newSiteDirPath = 'tmp_gh-pages/' + project.version + '/apidocs/'
new File(newSiteDirPath).mkdirs()
copy {
from 'build/docs/javadoc'
into newSiteDirPath
}
copy {
from 'README.md'
into 'tmp_gh-pages'
rename { filename -> filename.replace 'README', 'index' }
}
}
}
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. Regenerates the gh-pages branch under tmp_gh-pages
// 2. 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', 'uploadArchives'
}
}
}
// 1. Closes and releases the artifact on Sonatype
// 2. Commits and pushes the new docs
// 3. Removes tmp_gh-pages
// Note: This task assumes that the 'stageRelease' task has been completed.
task finalizeRelease {
dependsOn 'publishDocs'
doLast {
exec {
commandLine 'rm', '-r', 'tmp_gh-pages'
}
}
}