From 74282dd999035715a608f25bf212d32977e05c22 Mon Sep 17 00:00:00 2001 From: Andriy Redko Date: Wed, 3 Jan 2024 11:13:58 -0500 Subject: [PATCH] Refactor the runtime Java selection Signed-off-by: Andriy Redko --- .github/workflows/test-jdk8-compat-unit.yml | 2 +- .github/workflows/test-unit.yml | 15 ++++++++++- java-client/build.gradle.kts | 30 +++++++++------------ 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test-jdk8-compat-unit.yml b/.github/workflows/test-jdk8-compat-unit.yml index bf7bffc184..a5e73fce6e 100644 --- a/.github/workflows/test-jdk8-compat-unit.yml +++ b/.github/workflows/test-jdk8-compat-unit.yml @@ -27,4 +27,4 @@ jobs: cache: 'gradle' - name: Run Unit Test - run: ./gradlew clean unitTest -Pcheck-jdk8-compatibility=true + run: ./gradlew clean unitTest -Druntime.java=8 diff --git a/.github/workflows/test-unit.yml b/.github/workflows/test-unit.yml index 982d3d957a..14fa9a538f 100644 --- a/.github/workflows/test-unit.yml +++ b/.github/workflows/test-unit.yml @@ -7,7 +7,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - java: [ 11, 17, 21 ] + java: [ 8, 11, 17, 21 ] os: [ubuntu-latest, windows-latest, macOS-latest] steps: - name: Checkout Java Client @@ -21,4 +21,17 @@ jobs: cache: 'gradle' - name: Run Unit Test + if: ${{ matrix.java != 8 }} run: ./gradlew clean unitTest + + - name: Set up JDK 11 + uses: actions/setup-java@v3 + if: ${{ matrix.java == 8 }} + with: + java-version: 11 + distribution: 'temurin' + cache: 'gradle' + + - name: Run Unit Test + if: ${{ matrix.java == 8 }} + run: ./gradlew clean unitTest -D"runtime.java=8" diff --git a/java-client/build.gradle.kts b/java-client/build.gradle.kts index dd29517d09..ea80a59f33 100644 --- a/java-client/build.gradle.kts +++ b/java-client/build.gradle.kts @@ -64,6 +64,12 @@ configurations { } } +val runtimeJavaVersion = (System.getProperty("runtime.java")?.toInt())?.let(JavaVersion::toVersion) ?: JavaVersion.current() +logger.quiet("=======================================") +logger.quiet(" Runtime JDK Version : " + runtimeJavaVersion) +logger.quiet(" Gradle JDK Version : " + JavaVersion.current()) +logger.quiet("=======================================") + java { targetCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8 @@ -74,6 +80,11 @@ java { registerFeature("awsSdk2Support") { usingSourceSet(sourceSets.get("main")) } + + toolchain { + languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion) + vendor = JvmVendorSpec.ADOPTIUM + } } tasks.withType { @@ -338,9 +349,7 @@ publishing { } } -// Use `-Pcheck-jdk8-compatibility=true` to -val jdk8compatibility = (project.findProperty("check-jdk8-compatibility") as String?).toBoolean() -if (JavaVersion.current() >= JavaVersion.VERSION_11 && jdk8compatibility == false) { +if (runtimeJavaVersion >= JavaVersion.VERSION_11) { val java11: SourceSet = sourceSets.create("java11") { java { compileClasspath += sourceSets.main.get().output + sourceSets.test.get().output @@ -372,17 +381,4 @@ if (JavaVersion.current() >= JavaVersion.VERSION_11 && jdk8compatibility == fals testClassesDirs += java11.output.classesDirs classpath = sourceSets["java11"].runtimeClasspath } -} else if (jdk8compatibility == true) { - java { - toolchain { - languageVersion = JavaLanguageVersion.of(8) - vendor = JvmVendorSpec.ADOPTIUM - } - } - - tasks.register("tests-jdk8") { - javaLauncher = javaToolchains.launcherFor { - languageVersion = JavaLanguageVersion.of(8) - } - } -} +} \ No newline at end of file