summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Tubbs <ctubbsii@apache.org>2021-02-04 14:13:24 -0500
committerJens Geyer <jensg@apache.org>2021-02-04 22:10:30 +0100
commitebfa771a26e406da947f72ae8d87602c892435cc (patch)
tree057fa405165d395fefbabe9e7f505a25bbcdfcb9
parent518163afbd7c4f6733d12fa6f2de3db612fda947 (diff)
downloadthrift-ebfa771a26e406da947f72ae8d87602c892435cc.tar.gz
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.
-rw-r--r--lib/java/build.gradle5
-rw-r--r--lib/java/gradle/sourceConfiguration.gradle7
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/java/build.gradle b/lib/java/build.gradle
index 9184f7b97..57a8e1e26 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()
diff --git a/lib/java/gradle/sourceConfiguration.gradle b/lib/java/gradle/sourceConfiguration.gradle
index 07c2a7f1f..d15c1179f 100644
--- a/lib/java/gradle/sourceConfiguration.gradle
+++ b/lib/java/gradle/sourceConfiguration.gradle
@@ -46,6 +46,9 @@ sourceSets {
// ----------------------------------------------------------------------------
// Compiler configuration details
+// These two properties are still needed on JDK8, and possibly used directly by
+// plugins. However, the '--release' option added below makes these two
+// properties redundant when building with JDK9 or later.
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
@@ -53,6 +56,10 @@ tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
options.debug = true
options.deprecation = true
+ // the following is to build with Java 8 specifications, even when building with JDK9 or later
+ if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
+ options.compilerArgs.addAll(['--release', '8'])
+ }
// options.compilerArgs.addAll('-Xlint:unchecked')
}