forked from mongodb/mongo-kafka
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle.kts
448 lines (391 loc) · 14.4 KB
/
build.gradle.kts
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
/*
* Copyright 2008-present MongoDB, Inc.
*
* 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 com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.ByteArrayOutputStream
import java.net.URI
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
buildscript {
repositories {
mavenCentral()
}
}
plugins {
idea
`java-library`
`maven-publish`
signing
checkstyle
id("com.github.gmazzo.buildconfig") version "3.0.3"
id("com.github.spotbugs") version "4.7.9"
id("com.diffplug.spotless") version "5.17.1"
id("com.github.johnrengelman.shadow") version "6.1.0"
}
group = "org.mongodb.kafka"
version = "1.12.0-SNAPSHOT"
description = "The official MongoDB Apache Kafka Connect Connector."
repositories {
mavenCentral()
maven("https://packages.confluent.io/maven/")
maven("https://jitpack.io")
}
extra.apply {
set("mongodbDriverVersion", "[4.7,4.7.99)")
set("kafkaVersion", "2.6.0")
set("avroVersion", "1.9.2")
// Testing dependencies
set("junitJupiterVersion", "5.8.1")
set("junitPlatformVersion", "1.8.1")
set("hamcrestVersion", "2.2")
set("mockitoVersion", "4.0.0")
// Integration test dependencies
set("confluentVersion", "6.0.1")
set("scalaVersion", "2.13")
set("curatorVersion", "2.9.0")
set("connectUtilsVersion", "0.4+")
}
val mongoDependencies: Configuration by configurations.creating
val mongoAndAvroDependencies: Configuration by configurations.creating
dependencies {
implementation("org.apache.kafka:connect-api:${project.extra["kafkaVersion"]}")
implementation("org.mongodb:mongodb-driver-sync:${project.extra["mongodbDriverVersion"]}")
implementation("org.apache.avro:avro:${project.extra["avroVersion"]}")
mongoDependencies("org.mongodb:mongodb-driver-sync:${project.extra["mongodbDriverVersion"]}")
mongoAndAvroDependencies("org.mongodb:mongodb-driver-sync:${project.extra["mongodbDriverVersion"]}")
mongoAndAvroDependencies("org.apache.avro:avro:${project.extra["avroVersion"]}")
// Unit Tests
testImplementation(platform("org.junit:junit-bom:${project.extra["junitJupiterVersion"]}"))
testImplementation("org.junit.jupiter:junit-jupiter")
testImplementation("org.junit.platform:junit-platform-runner")
testImplementation("org.apiguardian:apiguardian-api:1.1.2") // https://github.com/gradle/gradle/issues/18627
testImplementation("org.hamcrest:hamcrest:${project.extra["hamcrestVersion"]}")
testImplementation("org.mockito:mockito-junit-jupiter:${project.extra["mockitoVersion"]}")
// Integration Tests
testImplementation("org.apache.curator:curator-test:${project.extra["curatorVersion"]}")
testImplementation("com.github.jcustenborder.kafka.connect:connect-utils:${project.extra["connectUtilsVersion"]}")
testImplementation(platform("io.confluent:kafka-schema-registry-parent:${project.extra["confluentVersion"]}"))
testImplementation(group = "com.google.guava", name = "guava")
testImplementation(group = "io.confluent", name = "kafka-schema-registry")
testImplementation(group = "io.confluent", name = "kafka-connect-avro-converter")
testImplementation(group = "org.apache.kafka", name = "connect-runtime")
testImplementation(group = "org.apache.kafka", name = "kafka-clients", classifier = "test")
testImplementation(group = "org.apache.kafka", name = "kafka-streams")
testImplementation(group = "org.apache.kafka", name = "kafka-streams", classifier = "test")
testImplementation(group = "org.scala-lang", name = "scala-library")
testImplementation(group = "org.apache.kafka", name = "kafka_${project.extra["scalaVersion"]}")
testImplementation(group = "org.apache.kafka", name = "kafka_${project.extra["scalaVersion"]}", classifier = "test")
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.release.set(8)
}
val defaultJdkVersion = 17
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(defaultJdkVersion))
}
}
/*
* Generated files
*/
val gitVersion: String by lazy {
val describeStdOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "describe", "--tags", "--always", "--dirty")
standardOutput = describeStdOut
}
describeStdOut.toString().substring(1).trim()
}
val gitDiffNameOnly: String by lazy {
val describeStdOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git", "diff", "--name-only")
standardOutput = describeStdOut
}
describeStdOut.toString().replaceIndent(" - ")
}
buildConfig {
className("Versions")
packageName("com.mongodb.kafka.connect")
useJavaOutput()
buildConfigField("String", "NAME", "\"mongo-kafka\"")
buildConfigField("String", "VERSION", provider { "\"${gitVersion}\"" })
}
/*
* Testing
*/
sourceSets.create("integrationTest") {
java.srcDir("src/integrationTest/java")
compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
runtimeClasspath += output + compileClasspath + sourceSets["test"].runtimeClasspath
}
tasks.create("integrationTest", Test::class.java) {
description = "Runs the integration tests"
group = "verification"
testClassesDirs = sourceSets["integrationTest"].output.classesDirs
classpath = sourceSets["integrationTest"].runtimeClasspath
outputs.upToDateWhen { false }
mustRunAfter("test")
}
tasks.withType<Test> {
tasks.getByName("check").dependsOn(this)
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
}
val javaVersion: Int = (project.findProperty("javaVersion") as String? ?: defaultJdkVersion.toString()).toInt()
logger.info("Running tests using JDK$javaVersion")
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(javaVersion))
})
systemProperties(mapOf("org.mongodb.test.uri" to System.getProperty("org.mongodb.test.uri", "")))
val jdkHome = project.findProperty("jdkHome") as String?
jdkHome.let {
val javaExecutablesPath = File(jdkHome, "bin/java")
if (javaExecutablesPath.exists()) {
executable = javaExecutablesPath.absolutePath
}
}
addTestListener(object : TestListener {
override fun beforeTest(testDescriptor: TestDescriptor?) {}
override fun beforeSuite(suite: TestDescriptor?) {}
override fun afterTest(testDescriptor: TestDescriptor?, result: TestResult?) {}
override fun afterSuite(d: TestDescriptor?, r: TestResult?) {
if (d != null && r != null && d.parent == null) {
val resultsSummary = """Tests summary:
| ${r.testCount} tests,
| ${r.successfulTestCount} succeeded,
| ${r.failedTestCount} failed,
| ${r.skippedTestCount} skipped""".trimMargin().replace("\n", "")
val border = "=".repeat(resultsSummary.length)
logger.lifecycle("\n$border")
logger.lifecycle("Test result: ${r.resultType}")
logger.lifecycle(resultsSummary)
logger.lifecycle("${border}\n")
}
}
})
}
/*
* Code checking
*/
checkstyle {
toolVersion = "7.4"
}
spotbugs {
excludeFilter.set(project.file("config/spotbugs-exclude.xml"))
showProgress.set(true)
setReportLevel("high")
setEffort("max")
}
tasks.withType<com.github.spotbugs.snom.SpotBugsTask> {
enabled = baseName.equals("main")
reports.maybeCreate("html").isEnabled = !project.hasProperty("xmlReports.enabled")
reports.maybeCreate("xml").isEnabled = project.hasProperty("xmlReports.enabled")
}
// Spotless is used to lint and reformat source files.
spotless {
java {
googleJavaFormat("1.12.0")
importOrder("java", "io", "org", "org.bson", "com.mongodb", "com.mongodb.kafka", "")
removeUnusedImports() // removes any unused imports
trimTrailingWhitespace()
endWithNewline()
indentWithSpaces()
}
kotlinGradle {
ktlint("0.30.0")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
format("extraneous") {
target("*.xml", "*.yml", "*.md")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
}
}
tasks.named("compileJava") {
dependsOn(":spotlessApply")
}
/*
* ShadowJar
*/
tasks.register<ShadowJar>("confluentJar") {
archiveClassifier.set("confluent")
from(mongoDependencies, sourceSets.main.get().output)
}
tasks.register<ShadowJar>("allJar") {
archiveClassifier.set("all")
from(mongoAndAvroDependencies, sourceSets.main.get().output)
}
tasks.withType<ShadowJar> {
archiveAppendix.set("connect")
doLast {
val fatJar = archiveFile.get().asFile
val fatJarSize = "%.4f".format(fatJar.length().toDouble() / (1_000 * 1_000))
println("FatJar: ${fatJar.path} ($fatJarSize MB)")
}
// Disable the default shadowJar task
tasks.named("shadowJar").configure {
enabled = false
}
}
/*
* Publishing
*/
tasks.register<Jar>("sourcesJar") {
description = "Create the sources jar"
from(sourceSets.main.get().allSource)
archiveClassifier.set("sources")
}
tasks.register<Jar>("javadocJar") {
description = "Create the Javadoc jar"
from(tasks.javadoc)
archiveClassifier.set("javadoc")
}
publishing {
publications {
create<MavenPublication>("mavenJava") {
artifactId = "mongo-kafka-connect"
from(components["java"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
artifact(tasks["confluentJar"])
artifact(tasks["allJar"])
pom {
name.set(project.name)
description.set(project.description)
url.set("http://www.mongodb.org")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
developers {
developer {
id.set("Various")
organization.set("MongoDB")
}
developer {
id.set("Hans-Peter Grahsl")
}
}
scm {
connection.set("scm:https://github.com/mongodb/mongo-kafka.git")
developerConnection.set("scm:[email protected]:mongodb/mongo-kafka.git")
url.set("https://github.com/mongodb/mongo-kafka")
}
}
}
}
repositories {
maven {
val snapshotsRepoUrl = URI("https://oss.sonatype.org/content/repositories/snapshots/")
val releasesRepoUrl = URI("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
url = if (version.toString().endsWith("SNAPSHOT")) snapshotsRepoUrl else releasesRepoUrl
credentials {
val nexusUsername: String? by project
val nexusPassword: String? by project
username = nexusUsername ?: ""
password = nexusPassword ?: ""
}
}
}
}
signing {
val signingKey: String? by project
val signingPassword: String? by project
useInMemoryPgpKeys(signingKey, signingPassword)
sign(publishing.publications["mavenJava"])
}
tasks.javadoc {
if (JavaVersion.current().isJava9Compatible) {
(options as StandardJavadocDocletOptions).addBooleanOption("html5", true)
}
}
tasks.register("publishSnapshots") {
group = "publishing"
description = "Publishes snapshots to Sonatype"
if (version.toString().endsWith("-SNAPSHOT")) {
dependsOn(tasks.withType<PublishToMavenRepository>())
}
}
tasks.register("publishArchives") {
group = "publishing"
description = "Publishes a release and uploads to Sonatype / Maven Central"
doFirst {
if (gitVersion != version) {
val cause = """
| Version mismatch:
| =================
|
| $version != $gitVersion
|
| Modified Files:
|$gitDiffNameOnly
|
| The project version does not match the git tag.
|""".trimMargin()
throw GradleException(cause)
} else {
println("Publishing: ${project.name} : $gitVersion")
}
}
if (gitVersion == version) {
dependsOn(tasks.withType<PublishToMavenRepository>())
}
}
// Confluent Archive
val releaseDate by extra(DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDateTime.now()))
val archiveFilename = "mongodb-kafka-connect-mongodb"
tasks.register<Copy>("prepareConfluentArchive") {
group = "Confluent"
description = "Prepares the Confluent Archive ready for the hub"
dependsOn("confluentJar")
val baseDir = "$archiveFilename-${project.version}"
from("config/archive/manifest.json") {
expand(project.properties)
destinationDir = file("$buildDir/confluentArchive/$baseDir")
}
from("config/archive/assets") {
into("assets")
}
from("config") {
include(listOf("MongoSinkConnector.properties", "MongoSourceConnector.properties"))
into("etc")
}
from("$buildDir/libs") {
include(listOf("${project.name}-connect-${project.version}-confluent.jar"))
into("lib")
}
from(".") {
include(listOf("README.md", "LICENSE.txt"))
into("doc")
}
}
tasks.register<Zip>("createConfluentArchive") {
group = "Confluent"
description = "Creates the Confluent Archive zipfile to be uploaded to the Confluent Hub"
dependsOn("prepareConfluentArchive")
from(files("$buildDir/confluentArchive"))
archiveBaseName.set("")
archiveAppendix.set(archiveFilename)
archiveVersion.set(project.version.toString())
destinationDirectory.set(file("$buildDir/confluent"))
}