Skip to content

Commit

Permalink
Try a different strategy for Java versions
Browse files Browse the repository at this point in the history
Always build using Java 11, and rely on Gradle to make that happen.
Support tests running on different versions via an environment variable.
  • Loading branch information
gbrail committed Sep 22, 2024
1 parent a24dfdc commit 459f933
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
37 changes: 29 additions & 8 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,46 @@ jobs:
strategy:
# Some tests require more CPU, and all can use multiple CPUs
max-parallel: 1
matrix:
java: [ '11', '17', '21' ]
name: Rhino Java ${{ matrix.java }}
name: Rhino Tests
steps:
- name: Checkout
- name: Check out Rhino
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
- name: Check out test262
# We don't actually want all the history for this part
run: git submodule update --init --single-branch
- name: Set up Java
uses: actions/setup-java@2dfa2011c5b2a0f1489bf9e433881c92c1631f88 # v4.3.0
with:
java-version: ${{ matrix.java }}
java-version: |
21
17
11
distribution: 'adopt'
- name: Check everything with Gradle
- name: Build and test Java 11
run: >-
./gradlew check
- name: Upload results
- name: Upload results Java 11
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: reports-java-${{ matrix.java }}
name: reports-java-11
path: '*/build/reports'
- name: Build and test Java 17
env:
RHINO_TEST_JAVA_VERSION: "17"
run: >-
./gradlew check
- name: Upload results Java 17
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: reports-java-17
path: '*/build/reports'
- name: Build and test Java 21
env:
RHINO_TEST_JAVA_VERSION: "21"
run: >-
./gradlew check
- name: Upload results Java 21
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4.4.0
with:
name: reports-java-21
path: '*/build/reports'
19 changes: 17 additions & 2 deletions buildSrc/src/main/groovy/rhino.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@ plugins {
id 'com.diffplug.spotless'
}

int testJavaVersion = -1
String jv = System.getenv("RHINO_TEST_JAVA_VERSION")
if (jv != null) {
testJavaVersion = Integer.parseInt(jv);
}

repositories {
mavenCentral()
}
Expand All @@ -19,11 +25,20 @@ dependencies {

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 11
options.compilerArgs = [
'-Xlint:deprecation,unchecked'
]
}

tasks.withType(Test) {
if (testJavaVersion > 0) {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(testJavaVersion)
}
}
}

test {
useJUnitPlatform()
}
Expand All @@ -32,9 +47,9 @@ spotless {
// There is no version of googleJavaFormat that works for Java 11 and 17,
// and different versions format differently. For now, only run spotless on Java 11.
// This will have to be changed when Java 11 support is removed.
if (JavaVersion.current() == JavaVersion.VERSION_11) {
if (JavaVersion.current() == JavaVersion.VERSION_21) {
java {
googleJavaFormat('1.10.0').aosp()
googleJavaFormat('1.17.0').aosp()
}
} else {
System.out.println("Not running Spotless: Java language version is " + JavaVersion.current())
Expand Down

0 comments on commit 459f933

Please sign in to comment.