Skip to content

Commit

Permalink
Build the test and low-level REST clients using Java 8.
Browse files Browse the repository at this point in the history
Signed-off-by: David Venable <[email protected]>
  • Loading branch information
dlvenable committed May 6, 2022
1 parent ad6bd4a commit 5283072
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
});
Expand All @@ -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<Integer> releaseVersionProviderFromCompileTask(Project project, AbstractCompile compileTask) {
return project.provider(() -> {
JavaVersion javaVersion = JavaVersion.toVersion(compileTask.getTargetCompatibility());
Expand Down
19 changes: 15 additions & 4 deletions client/rest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -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')
}

Expand Down
17 changes: 14 additions & 3 deletions client/test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit 5283072

Please sign in to comment.