forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
580 lines (502 loc) · 19.9 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
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
import com.github.spotbugs.snom.SpotBugsTask
import ru.vyarus.gradle.plugin.python.task.PythonTask
import com.hierynomus.gradle.license.tasks.LicenseFormat
// The buildscript block defines dependencies in order for .gradle file evaluation.
// This is separate from application dependencies.
// See https://stackoverflow.com/questions/17773817/purpose-of-buildscript-block-in-gradle.
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath 'com.bmuschko:gradle-docker-plugin:8.0.0'
// 6.x version of OpenApi generator is only compatible with jackson-core 2.13.x onwards.
// This conflicts with the jackson depencneis the bmuschko plugin is pulling in.
// Since api generation is only used in the airbyte-api module and the base gradle files
// are loaded in first, Gradle is not able to intelligently resolve this before loading in
// the bmuschko plugin and thus placing an older jackson version on the class path.
// The alternative is to import the openapi plugin for all modules.
// This might need to be updated when we change openapi plugin versions.
classpath 'com.fasterxml.jackson.core:jackson-core:2.13.0'
classpath 'org.codehaus.groovy:groovy-yaml:3.0.3'
}
}
plugins {
id 'base'
id 'pmd'
id 'com.diffplug.spotless' version '6.20.0'
id 'com.github.node-gradle.node' version '3.5.1'
id 'com.github.hierynomus.license' version '0.16.1'
id 'com.github.spotbugs' version '5.0.13'
id 'version-catalog'
id 'ru.vyarus.use-python'
}
repositories {
mavenCentral()
maven {
url 'https://airbyte.mycloudrepo.io/public/repositories/airbyte-public-jars/'
}
}
Properties env = new Properties()
rootProject.file('gradle.properties').withInputStream { env.load(it) }
if (!env.containsKey('VERSION')) {
throw new Exception('Version not specified in .env file...')
}
// `version` is used as the application build version for artifacts like jars
// `image_tag` is used as the docker tag applied to built images.
// These values are the same for building an specific Airbyte release or branch via the 'VERSION' environment variable.
// For local development builds, the 'VERSION' environment variable is unset, and built images are tagged with 'dev'.
ext {
version = System.getenv("VERSION") ?: env.VERSION
image_tag = System.getenv("VERSION") ?: 'dev'
}
allprojects {
apply plugin: 'base'
// by default gradle uses directory as the project name. That works very well in a single project environment but
// projects clobber each other in an environments with subprojects when projects are in directories named identically.
def sub = rootDir.relativePath(projectDir.parentFile).replace('/', '.')
group = "io.${rootProject.name}${sub.isEmpty() ? '' : ".$sub"}"
project.base.archivesName = "${project.group}-${project.name}"
version = rootProject.ext.version
}
def getCDKTargetVersion() {
def props = new Properties()
file("airbyte-cdk/java/airbyte-cdk/src/main/resources/version.properties").withInputStream { props.load(it) }
return props.getProperty('version')
}
static def getLatestFileModifiedTimeFromFiles(files) {
if (files.isEmpty()) {
return null
}
return files.findAll { it.isFile() }
.collect { it.lastModified() }
.max()
}
def checkCDKJarExists(requiredSnapshotVersion) {
if (requiredSnapshotVersion == null) {
// Connector does not require CDK snapshot.
return
}
final boolean checkFileChanges = true
final cdkTargetVersion = getCDKTargetVersion()
if (requiredSnapshotVersion != cdkTargetVersion) {
if (!cdkTargetVersion.contains("-SNAPSHOT")) {
throw new GradleException(
"CDK JAR version is not publishing snapshot but connector requires version ${requiredSnapshotVersion}.\n" +
"Please check that the version in the CDK properties file matches the connector build.gradle."
)
}
throw new GradleException(
"CDK JAR version ${cdkTargetVersion} does not match connector's required version ${requiredSnapshotVersion}.\n" +
"Please check that the version in the CDK properties file matches the connector build.gradle."
)
}
def cdkJar = file("${System.properties['user.home']}/.m2/repository/io/airbyte/airbyte-cdk/${cdkTargetVersion}/airbyte-cdk-${cdkTargetVersion}.jar")
if (!cdkJar.exists()) {
println("WARNING: CDK JAR does not exist at ${cdkJar.path}.\nPlease run './gradlew :airbyte-cdk:java:airbyte-cdk:build'.")
}
if (checkFileChanges) {
def latestJavaFileTimestamp = getLatestFileModifiedTimeFromFiles(file("${rootDir}/airbyte-cdk/java/airbyte-cdk/src").listFiles().findAll { it.isFile() })
if (cdkJar.lastModified() < latestJavaFileTimestamp) {
throw new GradleException("CDK JAR is out of date. Please run './gradlew :airbyte-cdk:java:airbyte-cdk:build'.")
}
}
}
static def getCDKSnapshotRequirement(dependenciesList) {
def cdkSnapshotRequirement = dependenciesList.find {
it.requested instanceof ModuleComponentSelector &&
it.requested.group == 'io.airbyte' &&
it.requested.module == 'airbyte-cdk' &&
it.requested.version.endsWith('-SNAPSHOT')
}
if (cdkSnapshotRequirement == null) {
return null
} else {
return cdkSnapshotRequirement.requested.version
}
}
// Common configurations for 'assemble'.
allprojects {
tasks.withType(Tar).configureEach {
duplicatesStrategy DuplicatesStrategy.INCLUDE
}
tasks.withType(Zip).configureEach {
duplicatesStrategy DuplicatesStrategy.INCLUDE
// Disabling distZip causes the build to break for some reason, so: instead of disabling it, make it fast.
entryCompression ZipEntryCompression.STORED
}
}
// Java projects common configurations.
subprojects { subproj ->
if (!subproj.file('src/main/java').directory) {
return
}
apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'com.github.spotbugs'
apply plugin: 'pmd'
java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
if (subproj.name.startsWith("source-") || subproj.name.startsWith("destination-")) {
// This is a Java connector project.
// Evaluate CDK project before evaluating the connector.
evaluationDependsOn(':airbyte-cdk:java:airbyte-cdk')
if (!gradle.startParameter.taskNames.any { it.contains(':airbyte-cdk:') } &&
gradle.startParameter.taskNames.any { it.contains(':source-') || it.contains(':destination-') }) {
// We are building a connector. Warn if the CDK JAR is missing or out of date.
final String cdkRelativePath = 'airbyte-cdk/java/airbyte-cdk'
afterEvaluate {
def cdkVersionNeeded = getCDKSnapshotRequirement(configurations.compileClasspath.incoming.resolutionResult.allDependencies)
checkCDKJarExists(cdkVersionNeeded)
}
}
}
repositories {
mavenCentral()
maven {
url 'https://jitpack.io'
}
maven {
url 'https://airbyte.mycloudrepo.io/public/repositories/airbyte-public-jars/'
}
mavenLocal()
}
pmd {
consoleOutput = true
ignoreFailures = false
rulesMinimumPriority = 5
ruleSets = []
ruleSetFiles = files(rootProject.file('tools/gradle/pmd/rules.xml'))
toolVersion = '6.51.0'
}
jacoco {
toolVersion = "0.8.8"
}
jacocoTestReport {
reports {
html.required = true
xml.required = true
csv.required = false
}
}
def jacocoTestReportTask = tasks.named('jacocoTestReport')
jacocoTestReportTask.configure {
dependsOn tasks.named('test')
}
jacocoTestCoverageVerification {
violationRules {
failOnViolation = false
rule {
element = 'CLASS'
excludes = ['**/*Test*', '**/generated*']
limit {
counter = 'BRANCH'
minimum = 0.8
}
limit {
counter = 'INSTRUCTION'
minimum = 0.8
}
}
}
}
// make tag accessible in submodules.
ext {
cloudStorageTestTagName = 'cloud-storage'
numberThreads = project.hasProperty('numberThreads')
? project.getProperty('numberThreads') as int
: Runtime.runtime.availableProcessors() ?: 1
}
spotbugs {
ignoreFailures = false
effort = 'max'
excludeFilter.set rootProject.file('spotbugs-exclude-filter-file.xml')
reportLevel = 'high'
showProgress = false
toolVersion = '4.7.3'
}
test {
//This allows to set up a `gradle.properties` file inside the connector folder to reduce number of threads and reduce parallelization.
//Specially useful for connectors that shares resources (like Redshift or Snowflake).
maxParallelForks = numberThreads
jacoco {
enabled = true
excludes = ['**/*Test*', '**/generated*']
}
useJUnitPlatform {
excludeTags(cloudStorageTestTagName)
}
testLogging() {
events "passed", "skipped", "failed"
exceptionFormat 'full'
// uncomment to get the full log output
// showStandardStreams = true
}
finalizedBy jacocoTestReportTask
}
dependencies {
if (subproj.name != 'airbyte-commons') {
implementation project(':airbyte-commons')
}
implementation(platform("com.fasterxml.jackson:jackson-bom:2.13.0"))
implementation(platform("org.glassfish.jersey:jersey-bom:2.31"))
// version is handled by "com.fasterxml.jackson:jackson-bom:2.10.4", so we do not explicitly set it here.
implementation libs.bundles.jackson
implementation libs.guava
implementation libs.commons.io
implementation libs.bundles.apache
implementation libs.slf4j.api
// SLF4J as a facade over Log4j2 required dependencies
implementation libs.bundles.log4j
// Bridges from other logging implementations to SLF4J
implementation libs.bundles.slf4j
// Dependencies for logging to cloud storage, as well as the various clients used to do so.
implementation libs.appender.log4j2
implementation libs.aws.java.sdk.s3
implementation libs.google.cloud.storage
implementation libs.s3
// Lombok dependencies
compileOnly libs.lombok
annotationProcessor libs.lombok
testCompileOnly libs.lombok
testAnnotationProcessor libs.lombok
testRuntimeOnly libs.junit.jupiter.engine
testImplementation libs.bundles.junit
testImplementation libs.assertj.core
testImplementation libs.junit.pioneer
// adds owasp plugin
spotbugsPlugins libs.findsecbugs.plugin
implementation libs.spotbugs.annotations
}
tasks.withType(SpotBugsTask).configureEach {
// Reports can be found under each subproject in build/spotbugs/
reports {
xml.required = false
html.required = true
}
}
tasks.withType(Pmd).configureEach {
exclude '**/generated/**'
exclude '**/jooq/**'
}
javadoc.options.addStringOption('Xdoclint:none', '-quiet')
tasks.named('check').configure {
dependsOn tasks.named('jacocoTestCoverageVerification')
}
}
// License generation logic.
def createLicenseWith = { File license, String startComment, String endComment, String lineComment, boolean isPython ->
/*
In java, we don't have a second linter/styling tool other than spotless so it doesn't really
matter if we write a newline or not for startComment/endComment.
However, in python, we are using black that double-checks and reformats the code.
Thus, writing an extra empty newline (not removed by trimTrailingWhitespace() is actually a
big deal and would be reformatted (removed) because of black's specs.
*/
def tmp = File.createTempFile('tmp', '.tmp')
tmp.withWriter {
def w = it
if (startComment.length() > 0 || !isPython) {
w.writeLine(startComment)
}
license.eachLine {
w << lineComment
w.writeLine(it)
}
if (endComment.length() > 0 || !isPython) {
w.writeLine(endComment)
}
w.writeLine("")
if (isPython) {
w.writeLine("")
}
}
return tmp
}
def createPythonLicenseWith = { license ->
return createLicenseWith(license, '', '', '', true)
}
def createJavaLicenseWith = { license ->
return createLicenseWith(license, '/*', ' */', ' * ', false)
}
// We are the spotless exclusions rules using file tree. It seems the excludeTarget option is super finicky in a
// monorepo setup and it doesn't actually exclude directories reliably. This code makes the behavior predictable.
def createSpotlessTarget = { pattern ->
def excludes = [
'.gradle',
'node_modules',
'.eggs',
'.mypy_cache',
'.venv',
'*.egg-info',
'build',
'dbt-project-template',
'dbt-project-template-mssql',
'dbt-project-template-mysql',
'dbt-project-template-oracle',
'dbt-project-template-clickhouse',
'dbt-project-template-snowflake',
'dbt-project-template-tidb',
'dbt-project-template-duckdb',
'dbt_test_config',
'normalization_test_output',
'tools',
'secrets',
'charts', // Helm charts often have injected template strings that will fail general linting. Helm linting is done separately.
'resources/seed/*_catalog.json', // Do not remove - this is also necessary to prevent diffs in our github workflows
'resources/seed/*_registry.json', // Do not remove - this is also necessary to prevent diffs in our github workflows
'resources/seed/specs_secrets_mask.yaml', // Downloaded externally.
'airbyte-integrations/connectors/source-amplitude/unit_tests/api_data/zipped.json', // Zipped file presents as non-UTF-8 making spotless sad
'airbyte-connector-builder-server/connector_builder/generated', // autogenerated code doesn't need to be formatted
'airbyte-ci/connectors/metadata_service/lib/tests/fixtures/**/invalid', // These are deliberately invalid and unformattable.
]
if (System.getenv().containsKey("SUB_BUILD")) {
excludes.add("airbyte-integrations/connectors")
}
return fileTree(dir: rootDir, include: pattern, exclude: excludes.collect { "**/${it}" })
}
// node is required by the root project to apply the prettier formatter repo-wide.
node {
download = true
version = '18.16.1'
npmVersion = '9.5.1'
// when setting both these directories, npm and node will be in separate directories
workDir = file("${buildDir}/nodejs")
npmWorkDir = file("${buildDir}/npm")
}
// Spotless is used by 'format'.
spotless {
java {
target createSpotlessTarget('**/*.java')
importOrder()
eclipse('4.21.0').configFile(rootProject.file('tools/gradle/codestyle/java-google-style.xml'))
licenseHeaderFile createJavaLicenseWith(rootProject.file('LICENSE_SHORT'))
removeUnusedImports()
trimTrailingWhitespace()
}
groovyGradle {
target createSpotlessTarget('**/*.gradle')
}
sql {
target createSpotlessTarget('**/*.sql')
dbeaver().configFile(rootProject.file('tools/gradle/codestyle/sql-dbeaver.properties'))
}
format 'styling', {
target createSpotlessTarget(['**/*.yaml', '**/*.json'])
prettier()
.npmExecutable("${tasks.named('npmSetup').get().npmDir.get()}/bin/npm") // get the npm executable path from gradle-node-plugin
.nodeExecutable("${tasks.named('nodeSetup').get().nodeDir.get()}/bin/node") // get the node executable path from gradle-node-plugin
}
}
tasks.named('spotlessStyling').configure {
dependsOn tasks.named('nodeSetup')
dependsOn tasks.named('npmSetup')
}
tasks.matching { it.name =~ /spotless.*Check/ }.configureEach {
enabled = false
}
// python is required by the root project to apply python formatters like isort or black.
python {
envPath = '.venv'
minPythonVersion = '3.9'
scope = 'VIRTUALENV'
installVirtualenv = true
pip 'pip:21.3.1'
pip 'black:22.3.0'
pip 'mypy:1.4.1'
pip 'isort:5.6.4'
}
// code and config generation is required for 'format'
def generateGlobal = tasks.register('generateGlobal')
generateGlobal.configure {
dependsOn allprojects.collect { tasks.matching { it.name == 'generate' } }
}
// python license header generation is part of 'format'
license {
header rootProject.file("LICENSE_SHORT")
}
def licensePythonGlobalFormat = tasks.register('licensePythonGlobalFormat', LicenseFormat) {
header = createPythonLicenseWith(rootProject.file('LICENSE_SHORT'))
source = fileTree(dir: rootProject.rootDir)
.include("**/*.py")
.exclude("**/.venv/**")
.exclude("**/build/**")
.exclude("**/node_modules/**")
.exclude("**/airbyte_api_client/**")
.exclude("**/__init__.py")
.exclude("airbyte-cdk/python/airbyte_cdk/sources/declarative/models/declarative_component_schema.py")
.exclude("airbyte-integrations/connectors/source-stock-ticker-api-tutorial/source.py")
.exclude("resources/examples/airflow/superset/docker/pythonpath_dev/superset_config.py")
.exclude("tools/git_hooks/tests/test_spec_linter.py")
.exclude("tools/schema_generator/schema_generator/infer_schemas.py")
strictCheck = true
}
licensePythonGlobalFormat.configure {
dependsOn generateGlobal
}
def isortGlobalFormat = tasks.register('isortGlobalFormat', PythonTask) {
module = "isort"
command = "--settings-file=${rootProject.file('pyproject.toml').absolutePath} ./"
}
isortGlobalFormat.configure {
dependsOn generateGlobal
dependsOn licensePythonGlobalFormat
}
def blackGlobalFormat = tasks.register('blackGlobalFormat', PythonTask) {
module = "black"
// the line length should match .isort.cfg
command = "--config ${rootProject.file('pyproject.toml').absolutePath} ./"
}
blackGlobalFormat.configure {
dependsOn generateGlobal
dependsOn licensePythonGlobalFormat
dependsOn isortGlobalFormat
}
def format = tasks.register('format') {}
format.configure {
dependsOn spotlessApply
dependsOn blackGlobalFormat
}
tasks.named('spotlessApply').configure {
dependsOn generateGlobal
}
// integration and performance test tasks per project
allprojects {
tasks.register('integrationTest') {
dependsOn tasks.matching {
[
'integrationTestJava',
'customIntegrationTests', // python integration tests
'connectorAcceptanceTest',
'standardSourceTestFile',
].contains(it.name)
}
}
tasks.register('performanceTest') {
dependsOn tasks.matching {
[
'performanceTestJava',
].contains(it.name)
}
}
}
// convenience task to list all dependencies per project
subprojects {
tasks.register('listAllDependencies', DependencyReportTask) {}
}
// produce reproducible archives
// (see https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives)
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
// pin dependency versions according to ./deps.toml
catalog {
versionCatalog {
from(files("deps.toml"))
}
}