Skip to content

Commit

Permalink
Refactor the runtime Java selection
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Redko <[email protected]>
  • Loading branch information
reta committed Jan 3, 2024
1 parent 220a560 commit 0c157de
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-jdk8-compat-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 14 additions & 1 deletion .github/workflows/test-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,4 +21,17 @@ jobs:
cache: 'gradle'

- name: Run Unit Test
if: ${{ matrix.os != 8 }}
run: ./gradlew clean unitTest

- name: Set up JDK 11
uses: actions/setup-java@v3
if: ${{ matrix.os == 8 }}
with:
java-version: 11
distribution: 'temurin'
cache: 'gradle'

- name: Run Unit Test
if: ${{ matrix.os == 8 }}
run: ./gradlew clean unitTest -Druntime.java=8
30 changes: 13 additions & 17 deletions java-client/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -74,6 +80,11 @@ java {
registerFeature("awsSdk2Support") {
usingSourceSet(sourceSets.get("main"))
}

toolchain {
languageVersion = JavaLanguageVersion.of(runtimeJavaVersion.majorVersion)
vendor = JvmVendorSpec.ADOPTIUM
}
}

tasks.withType<ProcessResources> {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<Test>("tests-jdk8") {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(8)
}
}
}
}

0 comments on commit 0c157de

Please sign in to comment.