From e18dbd89919893a90ed7a20951d74ada10d109e7 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 14 Oct 2021 12:13:10 -0400 Subject: [PATCH 1/4] Modernize and consolidate JDKs usage across all stages of the build. Update JDK-14 requirement, switch to JDK-17 instead Signed-off-by: Andriy Redko --- DEVELOPER_GUIDE.md | 8 ++++---- .../internal/fake_git/remote/.ci/java-versions.properties | 4 ++-- .../java/org/opensearch/gradle/test/DistroTestPlugin.java | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index e6d0aff55e061..4bf2e7c51c246 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -49,7 +49,7 @@ Fork [opensearch-project/OpenSearch](https://github.com/opensearch-project/OpenS OpenSearch builds using Java 11 at a minimum. This means you must have a JDK 11 installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK 11 installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-11`. -By default, tests use the same runtime as `JAVA_HOME`. However, since OpenSearch also supports JDK 8 as the runtime, the build supports compiling with JDK 11 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. +By default, the test tasks use bundled JDK runtime, configured in `buildSrc/version.properties` and set to JDK 17 (LTS). Other kind of test tasks (integration, cluster, ... ) use the same runtime as `JAVA_HOME`. However, since OpenSearch supports JDK 8/17 as the runtime, the build supports compiling with JDK 11 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. Alernatively, the runtime JDK version could be provided as the command line argument, using combination of `runtime.java=` property and `JAVA_HOME` environment variable, for exampe `./gradlew -Druntime.java=17 ...` (in this case, the tooling expects `JAVA17_HOME` environment variable to be set). To run the full suite of tests you will also need `JAVA8_HOME`, `JAVA11_HOME`, and `JAVA14_HOME`. They are required by the [backwards compatibility test](./TESTING.md#testing-backwards-compatibility). @@ -70,8 +70,8 @@ Start by running the test suite with `gradlew check`. This should complete witho OpenSearch Build Hamster says Hello! Gradle Version : 6.6.1 OS Info : Linux 5.4.0-1037-aws (amd64) - JDK Version : 14 (JDK) - JAVA_HOME : /usr/lib/jvm/java-14-openjdk-amd64 + JDK Version : 11 (JDK) + JAVA_HOME : /usr/lib/jvm/java-11-openjdk-amd64 ======================================= ... @@ -133,7 +133,7 @@ Use `-Dtests.opensearch.` to pass additional settings to the running instance. F ### IntelliJ IDEA -When importing into IntelliJ you will need to define an appropriate JDK. The convention is that **this SDK should be named "14"**, and the project import will detect it automatically. For more details on defining an SDK in IntelliJ please refer to [this documentation](https://www.jetbrains.com/help/idea/sdk.html#define-sdk). Note that SDK definitions are global, so you can add the JDK from any project, or after project import. Importing with a missing JDK will still work, IntelliJ will report a problem and will refuse to build until resolved. +When importing into IntelliJ you will need to define an appropriate JDK. The convention is that **this SDK should be named "11"**, and the project import will detect it automatically. For more details on defining an SDK in IntelliJ please refer to [this documentation](https://www.jetbrains.com/help/idea/sdk.html#define-sdk). Note that SDK definitions are global, so you can add the JDK from any project, or after project import. Importing with a missing JDK will still work, IntelliJ will report a problem and will refuse to build until resolved. You can import the OpenSearch project into IntelliJ IDEA as follows. diff --git a/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties b/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties index 51fc2b4015ef3..84e9b326dbead 100644 --- a/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties +++ b/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties @@ -27,6 +27,6 @@ # specific language governing permissions and limitations # under the License. # -OPENSEARCH_BUILD_JAVA=openjdk14 -OPENSEARCH_RUNTIME_JAVA=openjdk14 +OPENSEARCH_BUILD_JAVA=openjdk17 +OPENSEARCH_RUNTIME_JAVA=openjdk17 GRADLE_TASK=build diff --git a/buildSrc/src/main/java/org/opensearch/gradle/test/DistroTestPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/test/DistroTestPlugin.java index 8f66e263dcdd8..226875ec3d8e9 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/test/DistroTestPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/test/DistroTestPlugin.java @@ -76,8 +76,8 @@ public class DistroTestPlugin implements Plugin { private static final String SYSTEM_JDK_VERSION = "8u242+b08"; private static final String SYSTEM_JDK_VENDOR = "adoptopenjdk"; - private static final String GRADLE_JDK_VERSION = "14+36@076bab302c7b4508975440c56f6cc26a"; - private static final String GRADLE_JDK_VENDOR = "openjdk"; + private static final String GRADLE_JDK_VERSION = "17+35"; + private static final String GRADLE_JDK_VENDOR = "adoptium"; // all distributions used by distro tests. this is temporary until tests are per distribution private static final String EXAMPLE_PLUGIN_CONFIGURATION = "examplePlugin"; From f55b0ea1bf2ab584d43ffa9d2b43f0de2de0b3ee Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 14 Oct 2021 12:48:08 -0400 Subject: [PATCH 2/4] Updating phrasing based on review feedback Signed-off-by: Andriy Redko --- DEVELOPER_GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DEVELOPER_GUIDE.md b/DEVELOPER_GUIDE.md index 4bf2e7c51c246..a2e5836fc156e 100644 --- a/DEVELOPER_GUIDE.md +++ b/DEVELOPER_GUIDE.md @@ -49,7 +49,7 @@ Fork [opensearch-project/OpenSearch](https://github.com/opensearch-project/OpenS OpenSearch builds using Java 11 at a minimum. This means you must have a JDK 11 installed with the environment variable `JAVA_HOME` referencing the path to Java home for your JDK 11 installation, e.g. `JAVA_HOME=/usr/lib/jvm/jdk-11`. -By default, the test tasks use bundled JDK runtime, configured in `buildSrc/version.properties` and set to JDK 17 (LTS). Other kind of test tasks (integration, cluster, ... ) use the same runtime as `JAVA_HOME`. However, since OpenSearch supports JDK 8/17 as the runtime, the build supports compiling with JDK 11 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. Alernatively, the runtime JDK version could be provided as the command line argument, using combination of `runtime.java=` property and `JAVA_HOME` environment variable, for exampe `./gradlew -Druntime.java=17 ...` (in this case, the tooling expects `JAVA17_HOME` environment variable to be set). +By default, the test tasks use bundled JDK runtime, configured in `buildSrc/version.properties` and set to JDK 17 (LTS). Other kind of test tasks (integration, cluster, ... ) use the same runtime as `JAVA_HOME`. However, since OpenSearch supports JDK 8 as the runtime, the build supports compiling with JDK 11 and testing on a different version of JDK runtime. To do this, set `RUNTIME_JAVA_HOME` pointing to the Java home of another JDK installation, e.g. `RUNTIME_JAVA_HOME=/usr/lib/jvm/jdk-8`. Alernatively, the runtime JDK version could be provided as the command line argument, using combination of `runtime.java=` property and `JAVA_HOME` environment variable, for exampe `./gradlew -Druntime.java=17 ...` (in this case, the tooling expects `JAVA17_HOME` environment variable to be set). To run the full suite of tests you will also need `JAVA8_HOME`, `JAVA11_HOME`, and `JAVA14_HOME`. They are required by the [backwards compatibility test](./TESTING.md#testing-backwards-compatibility). From fe6157f1429c3caaa02bac0ba19bae2331383f30 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 14 Oct 2021 14:34:49 -0400 Subject: [PATCH 3/4] Fixed runtime Java version usage, it has to be respected when RUNTIME_JAVA_HOME == JAVA_HOME Signed-off-by: Andriy Redko --- .../gradle/info/GlobalBuildInfoPlugin.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java index 5ad7858846dae..c1e96a3d9401e 100644 --- a/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java +++ b/buildSrc/src/main/java/org/opensearch/gradle/info/GlobalBuildInfoPlugin.java @@ -65,6 +65,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Optional; import java.util.Random; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -75,7 +76,6 @@ public class GlobalBuildInfoPlugin implements Plugin { private static final String DEFAULT_LEGACY_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/LegacyESVersion.java"; private static final String DEFAULT_VERSION_JAVA_FILE_PATH = "server/src/main/java/org/opensearch/Version.java"; private static Integer _defaultParallel = null; - private static Boolean _isBundledJdkSupported = null; private final JavaInstallationRegistry javaInstallationRegistry; private final ObjectFactory objects; @@ -101,7 +101,8 @@ public void apply(Project project) { JavaVersion minimumCompilerVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumCompilerVersion")); JavaVersion minimumRuntimeVersion = JavaVersion.toVersion(Util.getResourceContents("/minimumRuntimeVersion")); - File runtimeJavaHome = findRuntimeJavaHome(); + Optional runtimeJavaHomeOpt = findRuntimeJavaHome(); + File runtimeJavaHome = runtimeJavaHomeOpt.orElse(Jvm.current().getJavaHome()); File rootDir = project.getRootDir(); GitInfo gitInfo = gitInfo(rootDir); @@ -113,7 +114,7 @@ public void apply(Project project) { params.reset(); params.setRuntimeJavaHome(runtimeJavaHome); params.setRuntimeJavaVersion(determineJavaVersion("runtime java.home", runtimeJavaHome, minimumRuntimeVersion)); - params.setIsRutimeJavaHomeSet(Jvm.current().getJavaHome().equals(runtimeJavaHome) == false); + params.setIsRutimeJavaHomeSet(runtimeJavaHomeOpt.isPresent()); params.setRuntimeJavaDetails(getJavaInstallation(runtimeJavaHome).getImplementationName()); params.setJavaVersions(getAvailableJavaVersions(minimumCompilerVersion)); params.setMinimumCompilerVersion(minimumCompilerVersion); @@ -262,14 +263,14 @@ private static void throwInvalidJavaHomeException(String description, File javaH throw new GradleException(message); } - private static File findRuntimeJavaHome() { + private static Optional findRuntimeJavaHome() { String runtimeJavaProperty = System.getProperty("runtime.java"); if (runtimeJavaProperty != null) { - return new File(findJavaHome(runtimeJavaProperty)); + return Optional.of(new File(findJavaHome(runtimeJavaProperty))); } - return System.getenv("RUNTIME_JAVA_HOME") == null ? Jvm.current().getJavaHome() : new File(System.getenv("RUNTIME_JAVA_HOME")); + return System.getenv("RUNTIME_JAVA_HOME") == null ? Optional.empty() : Optional.of(new File(System.getenv("RUNTIME_JAVA_HOME"))); } private static String findJavaHome(String version) { From 4349dbfd8315ab40117219d0bb7e01cefb68ae03 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Thu, 14 Oct 2021 14:50:41 -0400 Subject: [PATCH 4/4] Addressing review comments Signed-off-by: Andriy Redko --- .../internal/fake_git/remote/.ci/java-versions.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties b/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties index 84e9b326dbead..ded62500f1d30 100644 --- a/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties +++ b/buildSrc/src/integTest/resources/org/opensearch/gradle/internal/fake_git/remote/.ci/java-versions.properties @@ -27,6 +27,6 @@ # specific language governing permissions and limitations # under the License. # -OPENSEARCH_BUILD_JAVA=openjdk17 -OPENSEARCH_RUNTIME_JAVA=openjdk17 +OPENSEARCH_BUILD_JAVA=openjdk11 +OPENSEARCH_RUNTIME_JAVA=java8 GRADLE_TASK=build