From ad6bd4aea78e304c5042c35c746aee551e253a68 Mon Sep 17 00:00:00 2001 From: David Venable Date: Wed, 4 May 2022 10:03:59 -0500 Subject: [PATCH 1/2] Set the source and target compatibility for the opensearch-rest-client to Java 8. This project uses a client test library which is now also supporting Java 8. Signed-off-by: David Venable --- client/rest/build.gradle | 4 ++-- client/test/build.gradle | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/client/rest/build.gradle b/client/rest/build.gradle index 01c186ed83fc2..0e8930bb7380c 100644 --- a/client/rest/build.gradle +++ b/client/rest/build.gradle @@ -33,8 +33,8 @@ import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis apply plugin: 'opensearch.build' apply plugin: 'opensearch.publish' -targetCompatibility = JavaVersion.VERSION_11 -sourceCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_1_8 group = 'org.opensearch.client' archivesBaseName = 'opensearch-rest-client' diff --git a/client/test/build.gradle b/client/test/build.gradle index 07d874cf01ea7..7d1333a84eae7 100644 --- a/client/test/build.gradle +++ b/client/test/build.gradle @@ -29,8 +29,8 @@ */ apply plugin: 'opensearch.build' -targetCompatibility = JavaVersion.VERSION_11 -sourceCompatibility = JavaVersion.VERSION_11 +targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = JavaVersion.VERSION_1_8 group = "${group}.client.test" From 5283072f0f4108636efc8972627bfa393f059136 Mon Sep 17 00:00:00 2001 From: David Venable Date: Fri, 6 May 2022 10:40:49 -0500 Subject: [PATCH 2/2] Build the test and low-level REST clients using Java 8. Signed-off-by: David Venable --- .../gradle/OpenSearchJavaPlugin.java | 8 +++++++- client/rest/build.gradle | 19 +++++++++++++++---- client/test/build.gradle | 17 ++++++++++++++--- 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java index c701c47f9e68c..4360bccdee67c 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/OpenSearchJavaPlugin.java @@ -34,6 +34,7 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar; import nebula.plugin.info.InfoBrokerPlugin; +import org.gradle.jvm.toolchain.JavaLanguageVersion; import org.opensearch.gradle.info.BuildParams; import org.opensearch.gradle.info.GlobalBuildInfoPlugin; import org.opensearch.gradle.precommit.PrecommitTaskPlugin; @@ -174,7 +175,8 @@ public static void configureCompile(Project project) { compileTask.getConventionMapping().map("sourceCompatibility", () -> java.getSourceCompatibility().toString()); compileTask.getConventionMapping().map("targetCompatibility", () -> java.getTargetCompatibility().toString()); // The '--release is available from JDK-9 and above - if (BuildParams.getRuntimeJavaVersion().compareTo(JavaVersion.VERSION_1_8) > 0) { + if (BuildParams.getRuntimeJavaVersion().compareTo(JavaVersion.VERSION_1_8) > 0 + && getCompilerLanguageVersionOrDefault(compileTask).compareTo(JavaLanguageVersion.of(8)) > 0) { compileOptions.getRelease().set(releaseVersionProviderFromCompileTask(project, compileTask)); } }); @@ -186,6 +188,10 @@ public static void configureCompile(Project project) { }); } + private static JavaLanguageVersion getCompilerLanguageVersionOrDefault(JavaCompile compileTask) { + return compileTask.getJavaCompiler().map(c -> c.getMetadata().getLanguageVersion()).getOrElse(JavaLanguageVersion.of(11)); + } + private static Provider releaseVersionProviderFromCompileTask(Project project, AbstractCompile compileTask) { return project.provider(() -> { JavaVersion javaVersion = JavaVersion.toVersion(compileTask.getTargetCompatibility()); diff --git a/client/rest/build.gradle b/client/rest/build.gradle index 0e8930bb7380c..77b05c7a010e8 100644 --- a/client/rest/build.gradle +++ b/client/rest/build.gradle @@ -33,12 +33,23 @@ import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis apply plugin: 'opensearch.build' apply plugin: 'opensearch.publish' -targetCompatibility = JavaVersion.VERSION_1_8 -sourceCompatibility = JavaVersion.VERSION_1_8 - group = 'org.opensearch.client' archivesBaseName = 'opensearch-rest-client' +tasks.withType(JavaCompile).getByName('compileJava').configure { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + } + + options.compilerArgs -= '-Xlint:exports' + options.compilerArgs -= '-Xlint:module' + options.compilerArgs -= '-Xlint:opens' + options.compilerArgs -= '-Xlint:removal' + options.compilerArgs -= '-Xlint:requires-automatic' + options.compilerArgs -= '-Xlint:requires-transitive-automatic' + options.compilerArgs -= '-Xlint:preview' +} + dependencies { api "org.apache.httpcomponents:httpclient:${versions.httpclient}" api "org.apache.httpcomponents:httpcore:${versions.httpcore}" @@ -57,7 +68,7 @@ dependencies { } tasks.withType(CheckForbiddenApis).configureEach { - //client does not depend on server, so only jdk and http signatures should be checked + //client does not depend on shamcreerver, so only jdk and http signatures should be checked replaceSignatureFiles('jdk-signatures', 'http-signatures') } diff --git a/client/test/build.gradle b/client/test/build.gradle index 7d1333a84eae7..8fc9604b720d9 100644 --- a/client/test/build.gradle +++ b/client/test/build.gradle @@ -29,11 +29,22 @@ */ apply plugin: 'opensearch.build' -targetCompatibility = JavaVersion.VERSION_1_8 -sourceCompatibility = JavaVersion.VERSION_1_8 - group = "${group}.client.test" +tasks.withType(JavaCompile).getByName('compileJava').configure { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + } + + options.compilerArgs -= '-Xlint:exports' + options.compilerArgs -= '-Xlint:module' + options.compilerArgs -= '-Xlint:opens' + options.compilerArgs -= '-Xlint:removal' + options.compilerArgs -= '-Xlint:requires-automatic' + options.compilerArgs -= '-Xlint:requires-transitive-automatic' + options.compilerArgs -= '-Xlint:preview' +} + dependencies { api "org.apache.httpcomponents:httpcore:${versions.httpcore}" api "com.carrotsearch.randomizedtesting:randomizedtesting-runner:${versions.randomizedrunner}"