THRIFT-5274: Enforce Java 8 compatibility
Client: Java
Patch: Christopher Tubbs
This closes #2325
* Enforce Java 8 compatibility using the new `--release` flag introduced
in JDK9, so that all generated bytecode follows Java 8 strict
compatibility, even when building with newer JDK versions (9 or later)
(this fixes NoSuchMethodError with ByteBuffer, and other potential
incompatibilities in bytecode generation that would make the code
unable to run on a Java 8 JRE)
* Also strictly enforce the JDK version used to build the project by
ensuring it is at least version 1.8, and will fail fast when building
the Java libraries if this condition is not met.
diff --git a/lib/java/build.gradle b/lib/java/build.gradle
index 9184f7b..57a8e1e 100644
--- a/lib/java/build.gradle
+++ b/lib/java/build.gradle
@@ -19,6 +19,11 @@
// Using the legacy plugin classpath for Clover so it can be loaded optionally
buildscript {
+ // strictly enforce the minimum version of Java required to build and fail fast
+ if (JavaVersion.current() < JavaVersion.VERSION_1_8) {
+ throw new GradleException("The java version used is ${JavaVersion.current()}, but must be at least ${JavaVersion.VERSION_1_8}")
+ }
+
repositories {
mavenCentral()
google()