forked from airbytehq/airbyte
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
270 lines (224 loc) · 8.68 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
plugins {
id 'base'
id 'pmd'
id 'com.diffplug.spotless' version '5.7.0'
id 'com.github.hierynomus.license' version '0.15.0'
}
repositories {
mavenCentral()
}
Properties env = new Properties()
rootProject.file('.env').withInputStream { env.load(it) }
if (!env.containsKey('VERSION')) {
throw new Exception('Version not specified in .env file...')
}
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_data_tests',
'dbt_schema_tests',
'normalization_test_output',
'tools',
'secrets'
]
if (System.getenv().containsKey("CORE_ONLY")) {
excludes.add("airbyte-integrations/connectors")
}
return fileTree(dir: rootDir, include: pattern, exclude: excludes.collect { "**/${it}" })
}
spotless {
java {
target createSpotlessTarget('**/*.java')
importOrder()
eclipse('4.16.0').configFile(rootProject.file('tools/gradle/codestyle/java-google-style.xml'))
licenseHeaderFile createJavaLicenseWith(rootProject.file('LICENSE'))
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()
}
}
check.dependsOn 'spotlessApply'
allprojects {
apply plugin: 'base'
afterEvaluate { project ->
def composeDeps = [
":airbyte-config:init",
":airbyte-db",
":airbyte-migration",
":airbyte-scheduler:app",
":airbyte-server",
":airbyte-webapp",
].toSet().asImmutable()
if (project.getPath() in composeDeps) {
composeBuild.dependsOn(project.getPath() + ':assemble')
}
}
}
allprojects {
// 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.archivesBaseName = "${project.group}-${project.name}"
version = env.VERSION
}
// Java projects common configurations
subprojects {
if (project.name == 'airbyte-webapp' || project.name == 'airbyte-e2e-testing') {
return
}
apply plugin: 'java'
apply plugin: 'jacoco'
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
repositories {
mavenCentral()
}
pmd {
consoleOutput = true
rulePriority = 5
ruleSets = []
ruleSetFiles = files(rootProject.file('tools/gradle/pmd/rules.xml'))
}
test {
useJUnitPlatform()
testLogging() {
events 'failed'
exceptionFormat 'full'
// showStandardStreams = true
}
finalizedBy jacocoTestReport
}
jacocoTestReport {
dependsOn test
}
dependencies {
if (project.name != 'airbyte-commons') {
implementation project(':airbyte-commons')
}
implementation(platform("com.fasterxml.jackson:jackson-bom:2.10.4"))
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 'com.fasterxml.jackson.core:jackson-databind'
implementation 'com.fasterxml.jackson.core:jackson-annotations'
implementation 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml'
implementation group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'
implementation group: 'commons-io', name: 'commons-io', version: '2.7'
implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30'
// SLF4J as a facade over Log4j2 required dependencies
implementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.11.0'
implementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.11.0'
implementation group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.11.0'
// Bridges from other logging implementations to SLF4J
implementation group: 'org.slf4j', name: 'jul-to-slf4j', version: '1.7.30' // JUL bridge
implementation group: 'org.slf4j', name: 'jcl-over-slf4j', version: '1.7.30' //JCL bridge
implementation group: 'org.slf4j', name: 'log4j-over-slf4j', version: '1.7.30' // log4j1.2 bridge
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.1'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.1'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.7.1'
testImplementation group: 'org.mockito', name: 'mockito-junit-jupiter', version: '3.9.0'
}
}
task composeBuild {
def buildTag = System.getenv('VERSION') ?: 'dev'
doFirst {
exec {
workingDir rootDir
commandLine 'docker-compose', '-f', 'docker-compose.build.yaml', 'build', '--parallel', '--quiet'
environment 'VERSION', buildTag
}
}
}
build.dependsOn(composeBuild)
task('generate') {
dependsOn subprojects.collect { it.getTasksByName('generateSeed', true) }
dependsOn subprojects.collect { it.getTasksByName('generateProtocolClassFiles', true) }
dependsOn subprojects.collect { it.getTasksByName('generateJsonSchema2Pojo', true) }
}
task('format') {
dependsOn generate
dependsOn spotlessApply
dependsOn subprojects.collect { it.getTasksByName('airbytePythonFormat', true) }
}
// add licenses for python projects.
subprojects {
def pythonFormatTask = project.tasks.findByName('blackFormat')
if(pythonFormatTask != null) {
apply plugin: "com.github.hierynomus.license"
task licenseFormatPython(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
header = createPythonLicenseWith(rootProject.file('LICENSE'))
source = fileTree(dir: projectDir)
.include("**/*.py")
.exclude(".venv/**/*.py")
.exclude("**/__init__.py")
strictCheck = true
}
def licenseTask = project.tasks.findByName('licenseFormatPython')
blackFormat.dependsOn licenseTask
isortFormat.dependsOn licenseTask
flakeCheck.dependsOn licenseTask
def generateFilesTask = project.tasks.findByName('generateProtocolClassFiles')
if(generateFilesTask != null) {
licenseTask.dependsOn generateFilesTask
}
}
}
// produce reproducible archives
// (see https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives)
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}