@@ -28,6 +28,25 @@ plugins {
2828
2929defaultTasks ' clean' , ' build'
3030
31+ static def getBuildJavaVersion ()
32+ {
33+ def buildJavaVersion = System . getenv(' BUILD_JAVA_VERSION' ) ?: JavaVersion . current(). getMajorVersion()
34+ if (buildJavaVersion. indexOf(' .' ) > 0 )
35+ {
36+ buildJavaVersion = buildJavaVersion. substring(0 , buildJavaVersion. indexOf(' .' ))
37+ }
38+ if (buildJavaVersion. indexOf(' -' ) > 0 )
39+ {
40+ buildJavaVersion = buildJavaVersion. substring(0 , buildJavaVersion. indexOf(' -' ))
41+ }
42+ Integer . parseInt(buildJavaVersion)
43+ }
44+ int buildJavaVersion = getBuildJavaVersion()
45+
46+ def javaLauncher = javaToolchains. launcherFor {
47+ languageVersion = JavaLanguageVersion . of(buildJavaVersion)
48+ }
49+
3150def checkstyleVersion = ' 8.37'
3251def hamcrestVersion = ' 2.2'
3352def mockitoVersion = ' 3.6.0'
@@ -130,6 +149,10 @@ allprojects {
130149 failOnVersionConflict()
131150 }
132151 }
152+
153+ tasks. withType(JavaExec ). configureEach {
154+ executable = javaLauncher. get(). executablePath
155+ }
133156}
134157
135158jar. enabled = false
@@ -142,6 +165,12 @@ subprojects {
142165 group = sbeGroup
143166 version = sbeVersion
144167
168+ java {
169+ toolchain {
170+ languageVersion = JavaLanguageVersion . of(buildJavaVersion)
171+ }
172+ }
173+
145174 checkstyle. toolVersion = " ${ checkstyleVersion} "
146175
147176 tasks. withType(Sign ) {
@@ -156,7 +185,7 @@ subprojects {
156185 }
157186
158187 tasks. withType(JavaCompile ) {
159- if (JavaVersion . current() . isJava9Compatible() ) {
188+ if (buildJavaVersion >= 9 ) {
160189 options. compilerArgs. addAll([' --add-exports' , ' java.base/java.lang.reflect=ALL-UNNAMED' ])
161190 options. compilerArgs. addAll([' --add-exports' , ' jdk.unsupported/sun.misc=ALL-UNNAMED' ])
162191 }
@@ -172,18 +201,20 @@ subprojects {
172201 options. docEncoding = ' UTF-8'
173202 options. charSet = ' UTF-8'
174203 options. links(" https://www.javadoc.io/doc/org.agrona/agrona/${ agronaVersion} /" )
175- if (JavaVersion . current(). isJava11Compatible()) {
176- options. links(" https://docs.oracle.com/en/java/javase/${ JavaVersion.current().majorVersion} /docs/api/" )
204+ if (buildJavaVersion >= 16 ) { // Work around for early access versions for which no JavaDoc is published
205+ options. links(" https://docs.oracle.com/en/java/javase/15/docs/api/" )
206+ } else if (buildJavaVersion >= 11 ) {
207+ options. links(" https://docs.oracle.com/en/java/javase/${ buildJavaVersion} /docs/api/" )
177208 } else {
178- options. links(" https://docs.oracle.com/javase/${ JavaVersion.current().majorVersion } /docs/api/" )
209+ options. links(" https://docs.oracle.com/javase/${ buildJavaVersion } /docs/api/" )
179210 }
180- if (JavaVersion . current() . isJava10Compatible() ) {
211+ if (buildJavaVersion >= 10 ) {
181212 options. addBooleanOption ' html5' , true
182213 }
183214 }
184215
185216 test {
186- if (JavaVersion . current() . isJava9Compatible() ) {
217+ if (buildJavaVersion >= 9 ) {
187218 jvmArgs(' --add-opens' , ' java.base/java.lang.reflect=ALL-UNNAMED' )
188219 jvmArgs(' --add-exports' , ' jdk.unsupported/sun.misc=ALL-UNNAMED' )
189220 }
0 commit comments