From 983fc94610479341ac8ea2b71d92c2a15a80ab98 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 | 30 --------------------- .github/workflows/test-unit.yml | 15 ++++++++++- java-client/build.gradle.kts | 28 +++++++++---------- 3 files changed, 26 insertions(+), 47 deletions(-) delete mode 100644 .github/workflows/test-jdk8-compat-unit.yml diff --git a/.github/workflows/test-jdk8-compat-unit.yml b/.github/workflows/test-jdk8-compat-unit.yml deleted file mode 100644 index bf7bffc184..0000000000 --- a/.github/workflows/test-jdk8-compat-unit.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: Compatibility Unit Tests (JDK-8) - -on: [push, pull_request] - -jobs: - test: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macOS-latest] - steps: - - name: Checkout Java Client - uses: actions/checkout@v3 - - - name: Set up JDK 8 - uses: actions/setup-java@v3 - with: - java-version: 8 - distribution: 'temurin' - cache: 'gradle' - - - name: Set up JDK 11 - uses: actions/setup-java@v3 - with: - java-version: 11 - distribution: 'temurin' - cache: 'gradle' - - - name: Run Unit Test - run: ./gradlew clean unitTest -Pcheck-jdk8-compatibility=true 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..06c07a4b03 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) - } - } }