@@ -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,21 +61,6 @@ def javaMainProjects = javaProjects.findAll { !['util'].contains(it.name) }
6161def javaCodeCheckedProjects = javaMainProjects. findAll { ! [' driver-benchmarks' , ' driver-workload-executor' ]. contains(it. name) }
6262def 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-
7964configure(coreProjects) {
8065 apply plugin : ' idea'
8166
@@ -97,11 +82,8 @@ configure(coreProjects) {
9782configure(javaProjects) {
9883 apply plugin : ' java-library'
9984
100- java {
101- toolchain {
102- languageVersion = JavaLanguageVersion . of(DEFAULT_JDK_VERSION )
103- }
104- }
85+ sourceCompatibility = JavaVersion . VERSION_1_8
86+ targetCompatibility = JavaVersion . VERSION_1_8
10587
10688 sourceSets {
10789 main {
@@ -112,7 +94,6 @@ configure(javaProjects) {
11294 tasks. withType(GenerateModuleMetadata ) {
11395 enabled = false
11496 }
115-
11697}
11798
11899configure(scalaProjects) {
@@ -123,11 +104,8 @@ configure(scalaProjects) {
123104
124105 group = ' org.mongodb.scala'
125106
126- java {
127- toolchain {
128- languageVersion = JavaLanguageVersion . of(DEFAULT_JDK_VERSION )
129- }
130- }
107+ sourceCompatibility = JavaVersion . VERSION_1_8
108+ targetCompatibility = JavaVersion . VERSION_1_8
131109
132110 dependencies {
133111 compile (' org.scala-lang:scala-library:%scala-version%' )
@@ -175,7 +153,7 @@ configure(scalaProjects) {
175153configure(javaMainProjects) {
176154 apply plugin : ' nebula.optional-base'
177155 apply plugin : ' java-library'
178-
156+
179157 dependencies {
180158 compileOnly ' com.google.code.findbugs:jsr305:1.3.9'
181159 api ' org.slf4j:slf4j-api:1.7.6' , optional
@@ -352,6 +330,19 @@ configure(javaCodeCheckedProjects) {
352330 spotbugsTest {
353331 enabled = false
354332 }
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+ }
355346}
356347
357348def getGitVersion () {
@@ -366,3 +357,15 @@ def getGitVersion() {
366357apply from : ' gradle/publish.gradle'
367358apply from : ' gradle/deploy.gradle'
368359apply 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+ }
0 commit comments