Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Java 8 for opensearch-rest-client #3181

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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_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}"
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bulk replace at work? :)

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_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}"
Expand Down