@@ -28,6 +28,25 @@ plugins {
28
28
29
29
defaultTasks ' clean' , ' build'
30
30
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
+
31
50
def checkstyleVersion = ' 8.37'
32
51
def hamcrestVersion = ' 2.2'
33
52
def mockitoVersion = ' 3.6.0'
@@ -130,6 +149,10 @@ allprojects {
130
149
failOnVersionConflict()
131
150
}
132
151
}
152
+
153
+ tasks. withType(JavaExec ). configureEach {
154
+ executable = javaLauncher. get(). executablePath
155
+ }
133
156
}
134
157
135
158
jar. enabled = false
@@ -142,6 +165,12 @@ subprojects {
142
165
group = sbeGroup
143
166
version = sbeVersion
144
167
168
+ java {
169
+ toolchain {
170
+ languageVersion = JavaLanguageVersion . of(buildJavaVersion)
171
+ }
172
+ }
173
+
145
174
checkstyle. toolVersion = " ${ checkstyleVersion} "
146
175
147
176
tasks. withType(Sign ) {
@@ -156,7 +185,7 @@ subprojects {
156
185
}
157
186
158
187
tasks. withType(JavaCompile ) {
159
- if (JavaVersion . current() . isJava9Compatible() ) {
188
+ if (buildJavaVersion >= 9 ) {
160
189
options. compilerArgs. addAll([' --add-exports' , ' java.base/java.lang.reflect=ALL-UNNAMED' ])
161
190
options. compilerArgs. addAll([' --add-exports' , ' jdk.unsupported/sun.misc=ALL-UNNAMED' ])
162
191
}
@@ -172,18 +201,20 @@ subprojects {
172
201
options. docEncoding = ' UTF-8'
173
202
options. charSet = ' UTF-8'
174
203
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/" )
177
208
} 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/" )
179
210
}
180
- if (JavaVersion . current() . isJava10Compatible() ) {
211
+ if (buildJavaVersion >= 10 ) {
181
212
options. addBooleanOption ' html5' , true
182
213
}
183
214
}
184
215
185
216
test {
186
- if (JavaVersion . current() . isJava9Compatible() ) {
217
+ if (buildJavaVersion >= 9 ) {
187
218
jvmArgs(' --add-opens' , ' java.base/java.lang.reflect=ALL-UNNAMED' )
188
219
jvmArgs(' --add-exports' , ' jdk.unsupported/sun.misc=ALL-UNNAMED' )
189
220
}
0 commit comments