Skip to content

Commit 5bc28e9

Browse files
Use always latest toolchain and only run tests in old JVMs
1 parent 06e3158 commit 5bc28e9

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ jobs:
1212
- uses: actions/setup-java@v5
1313
with:
1414
distribution: temurin
15-
# The target JDK is used to build, the latest one to run Gradle itself (we cannot use Java 8 for Gradle)
15+
# Being in the last position, the latest JDK is used by default to build, the version from the matrix is made
16+
# available to run the tests, to check compatibility.
1617
java-version: |
1718
${{ matrix.java-version }}
1819
21
1920
20-
# delete gradle.properties in Java 8 because it contains a then-unsupported JVM argument: --add-exports
21-
- run: rm gradle.properties
22-
if: ${{ matrix.java-version == 8 }}
23-
2421
- run: ./gradlew assemble check --info
2522
env:
26-
JAVA_TOOLCHAIN: ${{ matrix.java-version }}
23+
TEST_JAVA_TOOLCHAIN: ${{ matrix.java-version }}

build.gradle

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,16 @@ plugins {
66
id "com.diffplug.spotless" version "7.2.1"
77
}
88

9-
var javaToolchain = System.getenv('JAVA_TOOLCHAIN')
10-
11-
java {
12-
if (javaToolchain != null) {
13-
toolchain {
14-
languageVersion = JavaLanguageVersion.of(javaToolchain)
15-
}
16-
}
17-
}
18-
199
compileJava {
20-
if (javaToolchain != "8") {
21-
options.release = 8
22-
}
23-
options.compilerArgs.add('-Xlint')
10+
options.release = 8
11+
// for some reason javac warns the previous option, disabling
12+
options.compilerArgs.add('-Xlint:all,-options')
2413
}
2514

2615
compileTestJava {
27-
if (javaToolchain != "8") {
28-
options.release = 8
29-
}
30-
options.compilerArgs.add('-Xlint')
16+
options.release = 8
17+
// for some reason javac warns the previous option, disabling
18+
options.compilerArgs.add('-Xlint:all,-options')
3119
}
3220

3321
repositories {
@@ -48,6 +36,17 @@ testing {
4836
suites {
4937
test {
5038
useJUnitJupiter()
39+
targets {
40+
all {
41+
testTask.configure {
42+
javaLauncher.set(
43+
javaToolchains.launcherFor {
44+
languageVersion.set(JavaLanguageVersion.of(System.getenv('TEST_JAVA_TOOLCHAIN')))
45+
}
46+
)
47+
}
48+
}
49+
}
5150
}
5251
}
5352
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package lbmq;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
/**
6+
* Not really a test, but a way of confirming that tests are running with the intended JVM version.
7+
*/
8+
public class VersionLoggerTest {
9+
10+
@Test
11+
public void versionLogger() {
12+
System.out.printf("Running in JVM version %s\n", System.getProperty("java.version"));
13+
}
14+
}

0 commit comments

Comments
 (0)