Skip to content

Commit f1afdec

Browse files
authored
KAFKA 271 (#93)
* Update gradlew to 7.3.1 Added gradle.properties to support spotless / google format java via compile exports Updated the following to support Java 17: * Spotless plugin * Spotbugs plugin * Buildconfig plugin * Junit 5 dependency * Mockito dependency * Hamcrest dependency KAFKA-271
1 parent 9950d8c commit f1afdec

File tree

12 files changed

+275
-178
lines changed

12 files changed

+275
-178
lines changed

.evergreen/config.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ functions:
273273
working_dir: "src"
274274
script: |
275275
${PREPARE_SHELL}
276-
JDK="${JDK}" .evergreen/run-unit-tests.sh
276+
javaVersion="${javaVersion}" .evergreen/run-unit-tests.sh
277277
278278
"run integration tests":
279279
- command: shell.exec
@@ -282,7 +282,7 @@ functions:
282282
working_dir: "src"
283283
script: |
284284
${PREPARE_SHELL}
285-
MONGODB_URI="${MONGODB_URI}" JDK="${JDK}" .evergreen/run-integration-tests.sh
285+
MONGODB_URI="${MONGODB_URI}" javaVersion="${javaVersion}" .evergreen/run-integration-tests.sh
286286
287287
"publish snapshots":
288288
- command: shell.exec
@@ -378,13 +378,17 @@ axes:
378378
variables:
379379
TOPOLOGY: "replica_set"
380380

381-
- id: "jdk"
382-
display_name: "JDK"
381+
- id: "javaVersion"
382+
display_name: "javaVersion"
383383
values:
384-
- id: "jdk8"
384+
- id: "JDK17"
385+
display_name: "JDK17"
386+
variables:
387+
JAVA_VERSION: "17"
388+
- id: "JDK8"
385389
display_name: "JDK8"
386390
variables:
387-
JDK: "jdk8"
391+
JAVA_VERSION: "8"
388392

389393
buildvariants:
390394

@@ -397,17 +401,17 @@ buildvariants:
397401
- name: "static-checks-task"
398402

399403
- matrix_name: "Unit-tests"
400-
matrix_spec: { jdk: "*", os: "*" }
401-
display_name: "Units tests: ${jdk}"
404+
matrix_spec: { javaVersion: "*", os: "*" }
405+
display_name: "Units tests: ${javaVersion}"
402406
tags: ["unit-test"]
403407
run_on:
404408
- "ubuntu1804-test"
405409
tasks:
406410
- name: "unit-test-task"
407411

408412
- matrix_name: "integration-tests"
409-
matrix_spec: { jdk: "*", version: "*", topology: "*", os: "*" }
410-
display_name: "Integration tests: ${jdk} ${version} ${topology} ${os}"
413+
matrix_spec: { javaVersion: "*", version: "*", topology: "*", os: "*" }
414+
display_name: "Integration tests: ${javaVersion} ${version} ${topology} ${os}"
411415
tags: ["integration-test"]
412416
run_on:
413417
- "ubuntu1804-test"

.evergreen/publish-snapshots.sh

100644100755
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ trap "rm ${PROJECT_DIRECTORY}/secring.gpg; exit" EXIT HUP
1212

1313
echo ${RING_FILE_GPG_BASE64} | base64 -d > ${PROJECT_DIRECTORY}/secring.gpg
1414

15-
echo "Publishing snapshot with jdk8"
15+
echo "Publishing snapshot with JDK17"
1616

17-
export JAVA_HOME="/opt/java/jdk8"
17+
export JDK8="/opt/java/jdk8"
18+
export JDK17="/opt/java/jdk17"
19+
export JAVA_HOME=$JDK17
1820

1921
export ORG_GRADLE_PROJECT_nexusUsername=${NEXUS_USERNAME}
2022
export ORG_GRADLE_PROJECT_nexusPassword=${NEXUS_PASSWORD}

.evergreen/run-integration-tests.sh

100644100755
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,21 @@ set -o xtrace # Write all commands first to stderr
44
set -o errexit # Exit the script with error if any of the commands fail
55

66
# Supported/used environment variables:
7-
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
8-
# JDK Set the version of java to be used. Java versions can be set from the java toolchain /opt/java "jdk8"
9-
7+
# JAVA_VERSION The version of java to use for the tests
8+
# MONGODB_URI Set the suggested connection MONGODB_URI (including credentials and topology info)
9+
JAVA_VERSION=${JAVA_VERSION:-17}
1010
MONGODB_URI=${MONGODB_URI:-}
11-
JDK=${JDK:-jdk}
12-
export JAVA_HOME="/opt/java/${JDK}"
11+
12+
export JDK8="/opt/java/jdk8"
13+
export JDK17="/opt/java/jdk17"
14+
export JAVA_HOME=$JDK17
1315

1416
############################################
1517
# Main Program #
1618
############################################
1719

1820

19-
echo "Running tests with ${JDK} connecting to $MONGODB_URI"
21+
echo "Running tests connecting to $MONGODB_URI on JDK${JAVA_VERSION}"
2022

2123
./gradlew -version
22-
./gradlew -Dorg.mongodb.test.uri=${MONGODB_URI} --stacktrace --info integrationTest
24+
./gradlew -PjavaVersion=$JAVA_VERSION -Dorg.mongodb.test.uri=${MONGODB_URI} --stacktrace --info integrationTest

.evergreen/run-static-checks.sh

100644100755
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
set -o xtrace # Write all commands first to stderr
44
set -o errexit # Exit the script with error if any of the commands fail
55

6-
export JAVA_HOME="/opt/java/jdk8"
6+
export JDK8="/opt/java/jdk8"
7+
export JDK17="/opt/java/jdk17"
8+
export JAVA_HOME=$JDK17
79

810
############################################
911
# Main Program #

.evergreen/run-unit-tests.sh

100644100755
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ set -o xtrace # Write all commands first to stderr
44
set -o errexit # Exit the script with error if any of the commands fail
55

66
# Supported/used environment variables:
7-
# JDK Set the version of java to be used. Java versions can be set from the java toolchain /opt/java "jdk8"
7+
# JAVA_VERSION The version of java to use for the tests
8+
JAVA_VERSION=${JAVA_VERSION:-17}
89

9-
JDK=${JDK:-jdk}
10-
export JAVA_HOME="/opt/java/${JDK}"
10+
export JDK8="/opt/java/jdk8"
11+
export JDK17="/opt/java/jdk17"
12+
export JAVA_HOME=$JDK17
1113

1214
############################################
1315
# Main Program #
1416
############################################
1517

16-
17-
echo "Running tests with ${JDK} connecting to $MONGODB_URI"
18+
echo "Running unit tests on JDK${JAVA_VERSION}"
1819

1920
./gradlew -version
20-
./gradlew --stacktrace --info test
21+
./gradlew -PjavaVersion=$JAVA_VERSION --stacktrace --info test
22+

build.gradle.kts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,19 @@ plugins {
3232
`maven-publish`
3333
signing
3434
checkstyle
35-
id("de.fuerstenau.buildconfig") version "1.1.8"
36-
id("com.github.spotbugs") version "4.6.0"
37-
id("com.diffplug.spotless") version "5.10.0"
35+
id("com.github.gmazzo.buildconfig") version "3.0.3"
36+
id("com.github.spotbugs") version "4.7.9"
37+
id("com.diffplug.spotless") version "5.17.1"
3838
id("com.github.johnrengelman.shadow") version "6.1.0"
3939
}
4040

4141
group = "org.mongodb.kafka"
4242
version = "1.7.0-SNAPSHOT"
4343
description = "The official MongoDB Apache Kafka Connect Connector."
4444

45-
java {
46-
sourceCompatibility = JavaVersion.VERSION_1_8
47-
targetCompatibility = JavaVersion.VERSION_1_8
48-
}
49-
5045
repositories {
5146
mavenCentral()
52-
maven("http://packages.confluent.io/maven/")
47+
maven("https://packages.confluent.io/maven/")
5348
maven("https://jitpack.io")
5449
}
5550

@@ -59,10 +54,10 @@ extra.apply {
5954
set("avroVersion", "1.9.2")
6055

6156
// Testing dependencies
62-
set("junitJupiterVersion", "5.4.0")
63-
set("junitPlatformVersion", "1.4.0")
64-
set("hamcrestVersion", "2.0.0.0")
65-
set("mockitoVersion", "2.27.0")
57+
set("junitJupiterVersion", "5.8.1")
58+
set("junitPlatformVersion", "1.8.1")
59+
set("hamcrestVersion", "2.2")
60+
set("mockitoVersion", "4.0.0")
6661

6762
// Integration test dependencies
6863
set("confluentVersion", "6.0.1")
@@ -85,9 +80,11 @@ dependencies {
8580
mongoAndAvroDependencies("org.apache.avro:avro:${project.extra["avroVersion"]}")
8681

8782
// Unit Tests
88-
testImplementation("org.junit.jupiter:junit-jupiter:${project.extra["junitJupiterVersion"]}")
89-
testImplementation("org.junit.platform:junit-platform-runner:${project.extra["junitPlatformVersion"]}")
90-
testImplementation("org.hamcrest:hamcrest-junit:${project.extra["hamcrestVersion"]}")
83+
testImplementation(platform("org.junit:junit-bom:${project.extra["junitJupiterVersion"]}"))
84+
testImplementation("org.junit.jupiter:junit-jupiter")
85+
testImplementation("org.junit.platform:junit-platform-runner")
86+
testImplementation("org.apiguardian:apiguardian-api:1.1.2") // https://github.com/gradle/gradle/issues/18627
87+
testImplementation("org.hamcrest:hamcrest:${project.extra["hamcrestVersion"]}")
9188
testImplementation("org.mockito:mockito-junit-jupiter:${project.extra["mockitoVersion"]}")
9289

9390
// Integration Tests
@@ -108,6 +105,14 @@ dependencies {
108105

109106
tasks.withType<JavaCompile> {
110107
options.encoding = "UTF-8"
108+
options.release.set(8)
109+
}
110+
111+
val defaultJdkVersion = 17
112+
java {
113+
toolchain {
114+
languageVersion.set(JavaLanguageVersion.of(defaultJdkVersion))
115+
}
111116
}
112117

113118
/*
@@ -123,18 +128,19 @@ val gitVersion: String by lazy {
123128
}
124129

125130
buildConfig {
126-
appName = "mongo-kafka"
127-
version = gitVersion
128-
clsName = "Versions"
129-
packageName = "com.mongodb.kafka.connect"
131+
className("Versions")
132+
packageName("com.mongodb.kafka.connect")
133+
useJavaOutput()
134+
buildConfigField("String", "NAME", "\"mongo-kafka\"")
135+
buildConfigField("String", "VERSION", provider { "\"${gitVersion}\"" })
130136
}
131137

132138
/*
133139
* Testing
134140
*/
141+
135142
sourceSets.create("integrationTest") {
136143
java.srcDir("src/integrationTest/java")
137-
resources.srcDir("src/integrationTest/resources")
138144
compileClasspath += sourceSets["main"].output + configurations["testRuntimeClasspath"]
139145
runtimeClasspath += output + compileClasspath + sourceSets["test"].runtimeClasspath
140146
}
@@ -155,6 +161,12 @@ tasks.withType<Test> {
155161
events("passed", "skipped", "failed")
156162
}
157163

164+
val javaVersion: Int = (project.findProperty("javaVersion") as String? ?: defaultJdkVersion.toString()).toInt()
165+
logger.info("Running tests using JDK$javaVersion")
166+
javaLauncher.set(javaToolchains.launcherFor {
167+
languageVersion.set(JavaLanguageVersion.of(javaVersion))
168+
})
169+
158170
systemProperties(mapOf("org.mongodb.test.uri" to System.getProperty("org.mongodb.test.uri", "")))
159171

160172
val jdkHome = project.findProperty("jdkHome") as String?
@@ -210,7 +222,7 @@ tasks.withType<com.github.spotbugs.snom.SpotBugsTask> {
210222
// Spotless is used to lint and reformat source files.
211223
spotless {
212224
java {
213-
googleJavaFormat()
225+
googleJavaFormat("1.12.0")
214226
importOrder("java", "io", "org", "org.bson", "com.mongodb", "com.mongodb.kafka", "")
215227
removeUnusedImports() // removes any unused imports
216228
trimTrailingWhitespace()

config/checkstyle/suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
<suppress checks="VisibilityModifier" files=".*RegExpSettings.java"/>
3333
<suppress checks="VisibilityModifier" files=".*RenameByRegExp.java"/>
3434

35+
<!-- Versions (generated code) -->
36+
<suppress checks="[a-zA-Z0-9]*" files="com[\\/]mongodb[\\/]kafka[\\/]connect[\\/]Versions.java" />
37+
3538
<!--Test code-->
3639
<suppress checks="[a-zA-Z0-9]*" files="com[\\/]mongodb[\\/]kafka[\\/]connect[\\/]avro[\\/]" />
3740
<suppress checks="[a-zA-Z0-9]*" files="com[\\/]mongodb[\\/]kafka[\\/]connect[\\/]embedded[\\/]" />

gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
org.gradle.java.installations.auto-download=false
2+
org.gradle.java.installations.fromEnv=JDK8,JDK17
3+
org.gradle.jvmargs=-XX:+HeapDumpOnOutOfMemoryError -Xmx1G --add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

gradle/wrapper/gradle-wrapper.jar

4.24 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)