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 01c186ed83fc2..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_11 -sourceCompatibility = JavaVersion.VERSION_11 - 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 07d874cf01ea7..8fc9604b720d9 100644 --- a/client/test/build.gradle +++ b/client/test/build.gradle @@ -29,11 +29,22 @@ */ apply plugin: 'opensearch.build' -targetCompatibility = JavaVersion.VERSION_11 -sourceCompatibility = JavaVersion.VERSION_11 - 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}"