Skip to content

Commit 1fe0761

Browse files
committed
Build: Added java toolchain to build.gradle
JAVA-4357
1 parent a7668fa commit 1fe0761

File tree

2 files changed

+29
-32
lines changed

2 files changed

+29
-32
lines changed

build.gradle

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ buildscript {
2727
classpath 'com.netflix.nebula:gradle-extra-configurations-plugin:3.0.3'
2828
classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.5.0"
2929
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:5.1.2'
30-
30+
3131
// Scala plugins
3232
classpath "com.adtran:scala-multiversion-plugin:1.0.36"
3333
classpath "com.diffplug.spotless:spotless-plugin-gradle:3.27.1"
@@ -61,6 +61,21 @@ def javaMainProjects = javaProjects.findAll { !['util'].contains(it.name) }
6161
def javaCodeCheckedProjects = javaMainProjects.findAll { !['driver-benchmarks', 'driver-workload-executor'].contains(it.name) }
6262
def javaAndScalaTestedProjects = javaCodeCheckedProjects + scalaProjects
6363

64+
tasks.withType(JavaCompile) {
65+
options.encoding = "UTF-8"
66+
options.release.set(8)
67+
}
68+
69+
final Integer DEFAULT_JDK_VERSION = 11
70+
71+
tasks.withType(Test) {
72+
def javaVersion = (findProperty("jdkVersion") ?: DEFAULT_JDK_VERSION.toString()).toInteger()
73+
logger.info("Running tests using JDK$javaVersion")
74+
javaLauncher.set(javaToolchains.launcherFor {
75+
languageVersion = JavaLanguageVersion.of(javaVersion)
76+
})
77+
}
78+
6479
configure(coreProjects) {
6580
apply plugin: 'idea'
6681

@@ -82,8 +97,11 @@ configure(coreProjects) {
8297
configure(javaProjects) {
8398
apply plugin: 'java-library'
8499

85-
sourceCompatibility = JavaVersion.VERSION_1_8
86-
targetCompatibility = JavaVersion.VERSION_1_8
100+
java {
101+
toolchain {
102+
languageVersion = JavaLanguageVersion.of(DEFAULT_JDK_VERSION)
103+
}
104+
}
87105

88106
sourceSets {
89107
main {
@@ -94,6 +112,7 @@ configure(javaProjects) {
94112
tasks.withType(GenerateModuleMetadata) {
95113
enabled = false
96114
}
115+
97116
}
98117

99118
configure(scalaProjects) {
@@ -104,8 +123,11 @@ configure(scalaProjects) {
104123

105124
group = 'org.mongodb.scala'
106125

107-
sourceCompatibility = JavaVersion.VERSION_1_8
108-
targetCompatibility = JavaVersion.VERSION_1_8
126+
java {
127+
toolchain {
128+
languageVersion = JavaLanguageVersion.of(DEFAULT_JDK_VERSION)
129+
}
130+
}
109131

110132
dependencies {
111133
compile ('org.scala-lang:scala-library:%scala-version%')
@@ -153,7 +175,7 @@ configure(scalaProjects) {
153175
configure(javaMainProjects) {
154176
apply plugin: 'nebula.optional-base'
155177
apply plugin: 'java-library'
156-
178+
157179
dependencies {
158180
compileOnly 'com.google.code.findbugs:jsr305:1.3.9'
159181
api 'org.slf4j:slf4j-api:1.7.6', optional
@@ -330,19 +352,6 @@ configure(javaCodeCheckedProjects) {
330352
spotbugsTest {
331353
enabled = false
332354
}
333-
334-
tasks.withType(Test) {
335-
def jdkHome = findProperty("jdkHome")
336-
if (jdkHome) {
337-
def javaExecutablesPath = new File(jdkHome, 'bin')
338-
def javaExecutables = [:].withDefault { execName ->
339-
def executable = new File(javaExecutablesPath, execName)
340-
assert executable.exists() : "There is no ${execName} executable in ${javaExecutablesPath}"
341-
executable
342-
}
343-
executable = javaExecutables.java
344-
}
345-
}
346355
}
347356

348357
def getGitVersion() {
@@ -357,15 +366,3 @@ def getGitVersion() {
357366
apply from: 'gradle/publish.gradle'
358367
apply from: 'gradle/deploy.gradle'
359368
apply from: 'gradle/javadoc.gradle'
360-
361-
//////////////////////////////////////////
362-
// Root project configuration //
363-
//////////////////////////////////////////
364-
365-
if (!JavaVersion.current().isJava9Compatible()) {
366-
throw new GradleException("""
367-
| ERROR:
368-
| JDK ${JavaVersion.VERSION_1_9.getMajorVersion()} is required to build the driver: You are using JDK ${JavaVersion.current().getMajorVersion()}.
369-
|""".stripMargin()
370-
)
371-
}

driver-core/src/main/com/mongodb/MongoCredential.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public static MongoCredential createPlainCredential(final String userName, final
293293
* {@code "JAVA_SUBJECT"} with the value of a {@code Subject} instance.
294294
* <p>
295295
* To override the properties of the {@link javax.security.sasl.SaslClient} with which the authentication executes, add a mechanism
296-
* property with the name {@code "JAVA_SASL_CLIENT_PROPERTIES"} with the value of a {@code Map<String, Object} instance containing the
296+
* property with the name {@code "JAVA_SASL_CLIENT_PROPERTIES"} with the value of a {@code Map<String, Object>} instance containing the
297297
* necessary properties. This can be useful if the application is customizing the default
298298
* {@link javax.security.sasl.SaslClientFactory}.
299299
*

0 commit comments

Comments
 (0)