-
Notifications
You must be signed in to change notification settings - Fork 125
Expand file tree
/
Copy pathbuild.gradle
More file actions
393 lines (343 loc) · 15.1 KB
/
Copy pathbuild.gradle
File metadata and controls
393 lines (343 loc) · 15.1 KB
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
/*
* build.gradle
*
* This source file is part of the FoundationDB open source project
*
* Copyright 2015-2018 Apple Inc. and the FoundationDB project authors
*
* 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.
*/
import org.apache.tools.ant.taskdefs.condition.Os
import org.yaml.snakeyaml.Yaml
import javax.inject.Inject
// Gives tasks access to an injected `ExecOperations` for running external processes from a `doLast` block.
interface InjectedExecOps {
@Inject
ExecOperations getExecOps()
}
buildscript {
repositories {
if (Boolean.parseBoolean(mavenLocalEnabled)) {
mavenLocal()
logger.warn 'Warning: you have enabled maven local repository. This should only be used on local workstations to test undeployed library dependencies.'
}
mavenCentral()
}
dependencies {
classpath 'org.jboss.tattletale:tattletale:1.2.0.Beta2'
classpath libs.snakeyaml
}
}
plugins {
alias(libs.plugins.protobuf)
alias(libs.plugins.spotbugs)
alias(libs.plugins.download)
}
ext {
fdbEnvironment = [:]
// Name of the directory (under the root project's build directory) that subprojects publish
// their artifacts into for publishing to Maven Central
stagingRepoDirName = 'staging-repo'
}
// Configure publishing to maven central.
//
// Both publishBuild and centralPublish must be set for these tasks to be registered at all.
// This avoids registering the tasks if we are not going to be publishing to maven central
if (Boolean.parseBoolean(publishBuild) && Boolean.parseBoolean(centralPublish)) {
apply from: rootProject.file('gradle/central-publishing.gradle')
}
defaultTasks 'build'
apply from: 'gradle/root.gradle'
def isReleaseBuild = Boolean.parseBoolean(getProperty('releaseBuild'))
allprojects {
apply plugin: 'base'
apply plugin: 'java-library'
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'project-reports'
apply plugin: 'de.undercouch.download'
// Configure all source files to be read using UTF-8
project.tasks.withType(JavaCompile) {
options.encoding = "utf-8"
}
project.tasks.withType(Javadoc) {
options.encoding = "utf-8"
}
project.tasks.withType(Test).configureEach {
systemProperty "file.encoding", "utf-8"
if (project.hasProperty("apiVersion")) {
systemProperty "com.apple.foundationdb.apiVersion", project.getProperty("apiVersion")
}
}
// Propagate debugging option to tests
// This makes sure that all tests are running in debug mode by default which is convenient, when e.g. working
// with IntelliJ because we do not have to set the 'debugBuild' configuration for each test individually,
// though this requires making sure that we set 'debugBuild' to false explicitly when producing a release
// or snapshot build to make sure that the tests are _not_ running in that mode and rather running in prod-like
// environment.
project.tasks.withType(Test).configureEach {
systemProperty "debugBuild", System.getProperty("debugBuild", "true")
dependsOn("sourcesJar")
}
layout.buildDirectory.set(layout.projectDirectory.dir(".out"))
ext {
distDir = ".dist"
}
// Add -SNAPSHOT to version of non-release builds
if (!isReleaseBuild) {
def versionString = project.version.toString()
if (!versionString.endsWith("-SNAPSHOT")) {
project.version = versionString + "-SNAPSHOT"
}
}
// Configure JUnit tests
tasks.withType(Test).configureEach {
reports.junitXml.outputLocation = project.layout.buildDirectory.dir("test-results")
}
def projectName = it.name
def projectVersion = it.version
// Configure JAR generation
tasks.jar.configure {
description = "Produces a Jar with the main classes in .out/."
manifest {
attributes "Built-JDK": System.getProperty("java.version"),
"Specification-Title": projectName,
"Specification-Version": "${-> projectVersion}",
"Specification-Vendor": "Apple Inc.",
"Implementation-Title": projectName,
"Implementation-Version": "${-> projectVersion}",
"Implementation-Vendor": "Apple Inc."
}
doFirst {
manifest {
attributes "Built-Date": new Date(),
"Built-By": System.getProperty("user.name")
}
}
}
// Create the sources jar
tasks.register('sourcesJar', Jar) {
dependsOn 'compileJava'
description = "Assembles a Jar archive containing the main sources."
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveAppendix = null
archiveClassifier = "sources"
from sourceSets.main.allSource
}
// Create the Javadoc jar
tasks.register('javadocJar', Jar) {
description = "Assembles a Jar archive containing the main Javadoc."
group = JavaBasePlugin.DOCUMENTATION_GROUP
archiveAppendix = null
archiveClassifier = "javadoc"
from tasks.named('javadoc')
}
// Distribution
tasks.register('createDistribution', Sync) {
// source directory depends on the subproject
into distDir
}
// Create umbrella task for all packaging operations
tasks.register('package', DefaultTask) {
description = "Produces main, sources, and Javadoc artifacts in .dist/."
dependsOn 'createDistribution'
}
build {
dependsOn tasks.named('jar'), tasks.named('package')
}
signing {
def signingKey = findProperty("signingKey")
def signingPassword = findProperty("signingPassword")
if (signingKey != null && signingPassword != null) {
useInMemoryPgpKeys(signingKey, signingPassword)
}
}
repositories {
if (System.getenv("ARTIFACT_VERSION") != null) {
version = "${System.getenv('ARTIFACT_VERSION')}"
} else if (System.getenv("RECORD_LAYER_BUILD_NUMBER") != null) {
version = "${version}.${System.getenv('RECORD_LAYER_BUILD_NUMBER')}"
}
if (Boolean.parseBoolean(mavenLocalEnabled)) {
mavenLocal()
logger.warn 'Warning: you have enabled maven local repository. This should only be used on local workstations to test undeployed library dependencies.'
}
mavenCentral()
}
}
subprojects {
apply from: rootProject.file('gradle/testing.gradle')
java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
// Pin `sourceCompatibility`/`targetCompatibility` to match the bytecode and API target that we set for
// `JavaCompile` tasks via `options.release` below. This also makes IntelliJ’s Gradle importer set the
// appropriate `languageLevel` in `.idea/misc.xml`.
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
def publishBuild = Boolean.parseBoolean(findProperty('publishBuild') ?: 'false')
def autoServiceVersion = publishBuild ? libs.versions.autoService.asProvider().get() : libs.versions.autoService.development.get()
project.configurations.all {
resolutionStrategy.eachDependency {details ->
if (details.requested.group == 'com.google.auto.service'
&& details.requested.name == 'auto-service') {
details.useVersion autoServiceVersion
}
}
}
def projectName = it.name
ext {
coreProjectName = "fdb-record-layer-core"
shadedProjectName = "fdb-record-layer-core-shaded"
publishLibrary = true
downloadsDirectory = rootProject.layout.projectDirectory.dir(".downloaded-build-assets/${projectName}")
}
tasks.named('assemble') {
dependsOn tasks.named('sourcesJar'), tasks.named('javadocJar'), tasks.named('testJar')
}
afterEvaluate { project ->
if (plugins.hasPlugin('java')) {
javadoc {
// exclude generated Protobuf classes
exclude "**/*Proto.java"
exclude "**/*ProtoV3.java"
exclude "com/apple/foundationdb/record/planprotos/*.java"
exclude "com/apple/foundationdb/record/query/plan/cascades/debug/eventprotos/*.java"
options.addBooleanOption('Xwerror', true)
// Quiet javadoc errors for missing comments, etc.
// It would be good to have more coverage, but this allows us to move forward with incomplete docs
options.addBooleanOption('Xdoclint:none', true)
options.addStringOption('source', '17')
options.with {
overview "src/main/javadoc/overview.html"
// Make our Javadocs link to external resources
// These use "linksOffline" in order to ensure that we can do offline builds as well as to tweak
// a few package lists. These should be periodically regenerated by running the
// ${packageListDir}/genpackagelists.py script. (See that script for more details.)
def packageListDir = "${project.rootDir}/build/package-lists"
linksOffline "https://apple.github.io/foundationdb/javadoc/", "${packageListDir}/fdb-java/"
linksOffline "https://developers.google.com/protocol-buffers/docs/reference/java/", "${packageListDir}/protobuf/"
// This is for dependent sub-projects so that their links to things in the Record Layer work
linksOffline "https://foundationdb.github.io/fdb-record-layer/api/fdb-extensions/", "${packageListDir}/fdb-extensions/"
linksOffline "https://foundationdb.github.io/fdb-record-layer/api/fdb-record-layer-core/", "${packageListDir}/fdb-record-layer-core/"
}
}
// Override some options on every compile task (main and test).
tasks.withType(JavaCompile).configureEach {
// Enable compilation in a separate daemon process.
options.fork = true
// Enable incremental compilation.
options.incremental = true
// Compile against the Java 17 API and emit Java 17 bytecode.
options.release = 17
}
}
}
apply from: rootProject.file('gradle/check.gradle')
apply from: rootProject.file('gradle/strict.gradle')
if(System.getenv("DO_NOT_CHECK") != null) {
task check(overwrite: true, dependsOn: 'quickCheck') { }
}
check.dependsOn 'quickCheck'
// At the end of a release build, we want to update all the yamsql files to replace !current_version with the
// version being built
tasks.register('updateYamsql') {
mustRunAfter 'test'
mustRunAfter 'build'
def execOps = objects.newInstance(InjectedExecOps).execOps
def projectVersion = project.version
def yamsqlFiles = sourceSets["test"].resources.srcDirs.collect { resourceDir ->
fileTree(dir: resourceDir).matching {
include '**/*.yamsql'
exclude '/initial-version/*'
exclude '/supported-version/*'
}
}
doLast {
if (isReleaseBuild) {
// don't replace !current_version in the supported-version resources, as those are there to test
// supported_version, we want the !current_version to stick around
println("Replacing !current_version...")
yamsqlFiles.each { tree ->
tree.each { yamsql ->
def original = yamsql.text
def updated = original.replaceAll("(?<!\")!current_version(?!\")", projectVersion)
if (original != updated) {
println("Replacing !current_version in " + yamsql)
// Replace !current_version in all yamsql, unless it is surrounded by ", allowing it to be used in
// comments, without issue, e.g. in showcasing-tests
yamsql.write(updated)
execOps.exec {
workingDir '.'
commandLine 'git', 'add', yamsql
}
}
}
}
}
}
}
}
// Script for upgrading gradle. To upgrade the gradle version, set the property to the version
// you want and run the command _twice_.
wrapper {
def gradleVersion = getProperty("gradleVersion") ?: project.gradle.gradleVersion
conventionMapping.distributionUrl = {
// use gradle-all rather than gradle-bin distribution because IntelliJ's Gradle integration
// works better with the former
"https://services.gradle.org/distributions/gradle-$gradleVersion-all.zip" as String
}
}
clean {
// Capture the distribution destination directories at configuration time so the configuration cache does not
// need to reach into `allprojects` from the `doLast` closure at execution time.
def distributionDirs = allprojects.collect { it.tasks.createDistribution.destinationDir }
doLast {
delete ".idea_build"
delete distributionDirs
}
}
apply from: 'gradle/sphinx.gradle'
// fdb-environment.properties is the old way we configured the library path and cluster file, it does not scale well
// to multiple cluster files, so is being replaced with a yaml file.
def fdbEnvironmentFile = new File("${rootProject.projectDir}/fdb-environment.properties")
if (fdbEnvironmentFile.exists()) {
fdbEnvironmentFile.eachLine { line ->
def eq = line.indexOf('=')
if (eq > 0) {
ext.fdbEnvironment.put(line.substring(0, eq), line.substring(eq + 1))
}
return
}
}
if (!ext.fdbEnvironment.isEmpty()) {
def fdbenv = ext.fdbEnvironment
allprojects {
tasks.withType(Test).configureEach { task ->
task.environment(fdbenv)
}
}
}
def fdbEnvironmentYamlFile = new File("${rootProject.projectDir}/fdb-environment.yaml")
if (fdbEnvironmentYamlFile.exists()) {
def libraryPath = new Yaml().loadAll(fdbEnvironmentYamlFile.newInputStream()).first().libraryPath
def libraryPathVariable = Os.isFamily(Os.FAMILY_MAC) ? "DYLD_LIBRARY_PATH" : "LD_LIBRARY_PATH"
allprojects {
tasks.withType(Test).configureEach { task ->
task.environment([(libraryPathVariable): libraryPath])
task.environment(FDB_ENVIRONMENT_YAML: fdbEnvironmentYamlFile.absolutePath)
}
}
}